PDA

View Full Version : $template call vs. echo=""; // loop.


Harlequin
01-28-2004, 10:01 AM
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 :


$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


$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:


$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
$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

$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
.=

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! :)