|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
gdboling Smarty Rookie
Joined: 20 Feb 2004 Posts: 31
|
Posted: Fri May 20, 2005 9:18 pm Post subject: mysql_fetch_assoc and section |
|
|
Can someone tell me why this isn't working.
Code: |
$result = mysql_query("select * from t_category", $pnp);
$results = array();
while($row = mysql_fetch_assoc($result)){
$results[] = $row;
}
$results = mysql_fetch_assoc($result);
$page->assign('results', $results);
$page->display('view_items.tpl');
|
Code: |
<table border="1">
{section name=item loop=$results}
<tr><td>
{$results[item].description}
</td></tr>
{/section}
</table>
|
I don't get anything in the {section}. I know it is pulling the data correctly because if I do the following in my php
echo $results[0]['description']; (looping over this of course)
I get the values I expect. It's just not working with section in my template.
Thanks. _________________ Gregg |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri May 20, 2005 9:21 pm Post subject: |
|
|
This might be part of the problem:
Code: | while($row = mysql_fetch_assoc($result)){
$results[] = $row;
}
$results = mysql_fetch_assoc($result); |
You loop through and assemble the $results array, then promptly overwrite it after the loop. |
|
Back to top |
|
gdboling Smarty Rookie
Joined: 20 Feb 2004 Posts: 31
|
Posted: Fri May 20, 2005 9:22 pm Post subject: |
|
|
mohrt wrote: | This might be part of the problem:
Code: | while($row = mysql_fetch_assoc($result)){
$results[] = $row;
}
$results = mysql_fetch_assoc($result); |
You loop through and assemble the $results array, then promptly overwrite it after the loop. |
DOH! Crap. Thanks. _________________ Gregg |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|