vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   $template call vs. echo=""; // loop. (https://vborg.vbsupport.ru/showthread.php?t=60852)

Harlequin 01-28-2004 10:01 AM

$template call vs. echo=""; // loop.
 
I'm beginning to get a little confused by something. Maybe my query needs to be changed for this.

In a nutshell, what is the difference between :

PHP Code:

$cc $DB_site->query(" SELECT * FROM tagio ");

while ( 
$cy $DB_site->fetch_array $cc ) ) :
$taglist "$cy[tags]";
endwhile;

// calling $taglist in the template
eval("dooutput(\"".gettemplate("cc_tag_test")."\");"); 


or

PHP Code:

$cc $DB_site->query(" SELECT * FROM tagio ");

while ( 
$cy $DB_site->fetch_array $cc ) ) :
$taglist ""$cy[tags] ."<br>";
endwhile;

// calling $taglist in the template
eval("dooutput(\"".gettemplate("cc_tag_test")."\");"); 


when compared to:

PHP Code:

$cc $DB_site->query(" SELECT * FROM tagio ");

while ( 
$cy $DB_site->fetch_array $cc ) ) :
echo 
"$cy[tags]";
endwhile; 

??


The problem is $taglist=""; in the template isn't calling the loop -- only the first result of the loop, while echo=""; calls everything in the loop fine and as it should.

I need the looped results to display in the template using $taglist - but apparently I'm doing something wrong here.

PS. Moved and erased this from another thread - was off-topic to that particular thread.

NTLDR 01-28-2004 10:44 AM

PHP Code:

$cc $DB_site->query("SELECT * FROM tagio"); 

while(
$cy $DB_site->fetch_array($cc)) {
    
$taglist .= $cy['tags'] .'<br />'
}

// calling $taglist in the template 
eval("dooutput(\"".gettemplate("cc_tag_test")."\");"); 

Note that its $taglist .= .... the . appends the content onto the end of the variable while just = overwrites it each time meaning that $taglist at the end only contains the last result from the query.

Brad 01-28-2004 10:51 AM

Use this to output via templates

PHP Code:

$pass '1';
while (
$query_array $DB_site->fetch_array($var))
{
    if (
$pass '1')
    {
        eval(
"\$output = \"".gettemplate('template')."\";");
    }
    else
    {
        eval(
"\$output .= \"<br /> ".gettemplate('template')."\";");
    }
    
$pass++;



g-force2k2 01-28-2004 11:00 AM

PHP Code:

.= 

Concatenation :)

Pretty much the reason was like NTLDR had stated, the concatenation is what adds the new info to the variable each time the loop passes. Once you add the concatenation to the variable there'll be no difference btw the three examples in general. Just using the variable allows placement in the template whether then echo'ing data before the tempate is output.

Cheers,
g-force2k2

Harlequin 01-28-2004 04:27 PM

You guys are wonderful. :)

Thank you all! :)


All times are GMT. The time now is 08:22 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.01123 seconds
  • Memory Usage 1,737KB
  • 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
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete