vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Help show more than one result. (https://vborg.vbsupport.ru/showthread.php?t=281224)

Preech 04-07-2012 04:20 AM

Help show more than one result.
 
So I'm working on creating a mod for music base sites. I am trying to show the output for all of the latest mixtapes that was posted. I can get the one to show. But the rest doesn't show. Maybe I messed up some where in the code. Here is what I got.

PHP Code:

// ###### YOUR CUSTOM CODE GOES HERE #####
$musicalbum =  $db->query_read("
SELECT al.alid, al.alname, al.arid, al.added, al.cvrsaved, ar.arname FROM " 
TABLE_PREFIX" album al
LEFT JOIN artist ar ON ar.arid=al.arid  
ORDER BY al.alid DESC LIMIT 5
"
);

    
    while (
$musical =$db->fetch_array($musicalbum))
    {
    
$malbumid $musical['alid'];
    
$malbumname $musical['alname'];
    
$malbumarname $musical['arname'];
    
$malbumarid $musical['arid'];
    
$mcvrsaved $musical['cvrsaved'];
    }
      


$musicstat $db->query_read("SELECT nr_artists, nr_albums,nr_tracks FROM " TABLE_PREFIX ." stats");
while (
$music_stat $db->fetch_array($musicstat))
{
$statar $music_stat['nr_artists'];
$statal $music_stat['nr_albums'];
$statt $music_stat['nr_tracks'];
}
    


    
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater vB_Template::create('vbmusic');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('malbumid'$malbumid);
$templater->register('malbumname'$malbumname);
$templater->register('malbumarname'$malbumarname);
$templater->register('malbumarid'$malbumarid);
$templater->register('cvrsaved'$cvrsaved);
$templater->register('statar'$statar);
$templater->register('statal'$statal);
$templater->register('statt'$statt);
$templater->register('mar1'$mar1);
$templater->register('vbmusic_latest'$vbmusic_latest);  
print_output($templater->render()); 

this is my template.
PHP Code:

<div class="audio_body2">
<
span class="column">
 <
div class="box">
<
center>
<
vb:if condition="$my_variable == yes">
    <
img src="./audio/covers/{vb:raw cvrsaved}/jpg" width="130px" border="0" ">
<vb:else />
    <img src="
./audio/covers/no_cover.jpg" width="130px" border="0" ">
</
vb:if>
</
center>
</
div>
<
hr style="height: 1;
 border-style: dashed;
 border-width: 1px 0 0 0;
 border-color:rgb(255, 255, 255) url(images/gradients/grey-up.png) repeat-x left bottom;"
>
  <
div class="box">Album:&nbsp <a href="./vbmusic_album.php?id=".$row1['alid']."\">{vb:raw malbumname}</a></div>
  <div class="
box">Artist:&nbsp<a href="./artist.php?id={vb:raw malbumarid}">{vb:raw malbumarname}</a></div>
</span>
</div> 

and this is the code I'm using to pull this template into my main template.
PHP Code:

{vb:raw vbmusic_latest

Please point me in the right direction.

Pandemikk 04-07-2012 04:42 AM

You need to register your template for use in another template: https://vborg.vbsupport.ru/showthread.php?t=228078

Save your template into a variable then preregister that variable into the main template. The variable will contain the HTML and parsed template syntax ready for use in the main template.

Btw: You should wrap:
PHP Code:

if ($db->num_rows($result))
{
    
// while here


Prevents errors on empty results.

Preech 04-07-2012 04:44 AM

Am I putting this before my while statment, or would it be smarter to try using the foreach. I'm guessing my issue is all in my php page.

Pandemikk 04-07-2012 04:55 AM

I think I've mistaken what you're trying to do.

You want: {vb:raw vbmusic_latest}

To contain the contents of the HTML you posted in your first post? Assuming it's a template,

PHP Code:

$templater vB_Template::create('YOURTEMPLATE');
$templater->register('malbumid'$malbumid);
$templater->register('malbumname'$malbumname);
$templater->register('malbumarname'$malbumarname);
$templater->register('malbumarid'$malbumarid); 
$vbmusic_latest $templater->render(); 


Preech 04-07-2012 05:03 AM

Yes, {vb:raw vbmusic_latest} contains all of the html.
Negative on showing up though. I'm guessing I have to do a foreach statement.

Pandemikk 04-07-2012 05:18 AM

Lol no.

Are you sure $vbmusic_latest contains the proper HTML?

PHP Code:

var_dump($vbmusic_latest); die; 

Put this right above where your template gets rendered. What do you see?

Preech 04-07-2012 05:35 AM

after pasting this. I see NULL. No I know some where I'm messing up with registering the template to show.

Pandemikk 04-07-2012 05:46 AM

Your code doesn't show $vbmusic_latest being registered at all. ;)

Preech 04-07-2012 05:54 AM

PHP Code:

$musicalbum =  $db->query_read("
SELECT al.alid, al.alname, al.arid, al.added, al.cvrsaved, ar.arname FROM " 
TABLE_PREFIX" album al
LEFT JOIN artist ar ON ar.arid=al.arid  
ORDER BY al.alid DESC LIMIT 5
"
);
if (
$db->num_rows($musicalbum))
{
    while (
$musical =$db->fetch_array($musicalbum))
    {
    
$malbumid $musical['alid'];
    
$malbumname $musical['alname'];
    
$malbumarname $musical['arname'];
    
$malbumarid $musical['arid'];
    
$mcvrsaved $musical['cvrsaved'];
    }





}

$musicstat $db->query_read("SELECT nr_artists, nr_albums,nr_tracks FROM " TABLE_PREFIX ." stats");
while (
$music_stat $db->fetch_array($musicstat))
{
$statar $music_stat['nr_artists'];
$statal $music_stat['nr_albums'];
$statt $music_stat['nr_tracks'];
}
    



// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater vB_Template::create('vbmusic');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('malbumid'$malbumid);
$templater->register('malbumname'$malbumname);
$templater->register('malbumarname'$malbumarname);
$templater->register('malbumarid'$malbumarid);
$templater->register('vbmusic_latest'$vbmusic_latest);
$templater->register('cvrsaved'$cvrsaved);
$templater->register('statar'$statar);
$templater->register('statal'$statal);
$templater->register('statt'$statt);
$vbmusic_latest $templater->render();
print_output($templater->render()); 

First off I appreciate all of the help. This is the php page.
1. The vbmusic_latest template still doesn't show.
2. For each album id, I want to display that album. I've looked through the original vb files. The closest would be foreach, but I'm lost now.

Pandemikk 04-07-2012 07:00 AM

1) Let's work on getting you to actually show your template first. :)

You really should look at that article I posted, because you're still doing it all wrong.

PHP Code:

$templater vB_Template::create('vbmusic');
    
$templater->register('malbumid'$malbumid);
    
$templater->register('malbumname'$malbumname);
    
$templater->register('malbumarname'$malbumarname);
    
$templater->register('malbumarid'$malbumarid); 
$vbmusic_latest $templater->render();  

$templater vB_Template::create('GENERIC_SHELL');
    
$templater->register_page_templates(); 
    
$templater->register('navbar'$navbar);
    
$templater->register('vbmusic_latest'$vbmusic_latest);
    
$templater->register('cvrsaved'$cvrsaved);
    
$templater->register('statar'$statar);
    
$templater->register('statal'$statal);
    
$templater->register('statt'$statt);
print_output($templater->render()); 



All times are GMT. The time now is 10:41 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01287 seconds
  • Memory Usage 1,806KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete