Forum Moderators: coopster

Message Too Old, No Replies

Loops in template class

         

nedloh

4:37 pm on Sep 7, 2007 (gmt 0)

10+ Year Member



I wrote a template class and now when i go to parse data that should loop, it will just parse the last entered field

[code}$map = $row['map'];
$win = $row['result'];

$output = "
<table border=\"0\" width=\"100%\" id=\"table3\">

<tr>
<td bgcolor=\"#657685\" width=\"26%\" align=\"center\"><b>
<font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">
$row[team]</font></b></td>
<td bgcolor=\"#657685\" width=\"38%\" align=\"center\">
<font color=\"#FFFFFF\" size=\"1\" face=\"Verdana\">
$row[map]</font></td>
<td bgcolor=\"#657685\" width=\"17%\">
<p align=\"center\">
<font size=\"1\" face=\"Verdana\" color=\"#FFFFFF\">$row[roundwon] - $row[roundlost]</font></p></td>
<td bgcolor=\"#657685\" width=\"11%\">
<p align=\"center\"><b>
<font color=\"$color\" size=\"2\" face=\"Verdana\">$row[result]</font></b></p></td>
</tr>
</table></td>
</tr>
";

};
[/code] That is the code that fetches the information.

and here is the info for the template array


"MATCHES" =>"$output",

Also, the rest of the template class works fie but i don't know how im going to make it "loopable" as such. Any ideas will help.

eelixduppy

5:25 pm on Sep 7, 2007 (gmt 0)



You cannot include array values in a string like you have. It should be changed to one of the following ways to work correctly:

$output = "
<table border=\"0\" width=\"100%\" id=\"table3\">
<tr>
<td bgcolor=\"#657685\" width=\"26%\" align=\"center\"><b>
<font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">
{$row['team']}</font></b></td>
<td bgcolor=\"#657685\" width=\"38%\" align=\"center\">
<font color=\"#FFFFFF\" size=\"1\" face=\"Verdana\">
{$row['map']}</font></td>
<td bgcolor=\"#657685\" width=\"17%\">
<p align=\"center\">
<font size=\"1\" face=\"Verdana\" color=\"#FFFFFF\">{$row['roundwon']} - {$row['roundlost']}</font></p></td>
<td bgcolor=\"#657685\" width=\"11%\">
<p align=\"center\"><b>
<font color=\"$color\" size=\"2\" face=\"Verdana\">{$row['result']}</font></b></p></td>
</tr>
</table></td>
</tr>
";

or taken out of the quotes completely:


$output = "
<table border=\"0\" width=\"100%\" id=\"table3\">
<tr>
<td bgcolor=\"#657685\" width=\"26%\" align=\"center\"><b>
<font face=\"Verdana\" size=\"1\" color=\"#FFFFFF\">
".$row['team']."</font></b></td>
<td bgcolor=\"#657685\" width=\"38%\" align=\"center\">
<font color=\"#FFFFFF\" size=\"1\" face=\"Verdana\">
".$row['map']."</font></td>
<td bgcolor=\"#657685\" width=\"17%\">
<p align=\"center\">
<font size=\"1\" face=\"Verdana\" color=\"#FFFFFF\">".$row['roundwon']." - ".$row['roundlost']."</font></p></td>
<td bgcolor=\"#657685\" width=\"11%\">
<p align=\"center\"><b>
<font color=\"$color\" size=\"2\" face=\"Verdana\">".$row['result']."</font></b></p></td>
</tr>
</table></td>
</tr>
";

nedloh

5:40 pm on Sep 7, 2007 (gmt 0)

10+ Year Member



Nah, had no effect. Thanks for the try though :S

dreamcatcher

6:02 pm on Sep 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your code is looping you`ll need to concatenate the var. If you don`t each loop overwrites the last:

$output .= "

dc

nedloh

11:58 pm on Sep 7, 2007 (gmt 0)

10+ Year Member



LMAO! I can't believe i didn't already do that LMAO! Thanks for pointing that out :)

eelixduppy

12:00 am on Sep 8, 2007 (gmt 0)



hehe - nice catch dreamcatcher. :)

nedloh, even though it might work, you should make those changes I pointed out above as it may create a problem for you as it's not the correct syntax for putting array elements within a string.

nedloh

4:54 am on Sep 8, 2007 (gmt 0)

10+ Year Member



Will do, i was wondering if there was an easy way to keep parsing a tpl file till there areno more results left? I was thinking of doing a


while(!$id == $count){
$template->parse("news");
};

$count would be mysql_num_rows of course
Do you think that would work?

nedloh

6:43 am on Sep 8, 2007 (gmt 0)

10+ Year Member



Nope, didn't work. just looped infinite

nedloh

10:43 am on Sep 8, 2007 (gmt 0)

10+ Year Member



Its fine. I fixed it, i was using something the wrong way. Thanks for pointing out my coding mistake DC ;)