RE: [SMARTY] Smarty PHP Question

From: Date: Sat, 17 Aug 2002 21:55:31 +0000
Subject: RE: [SMARTY] Smarty PHP Question
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5735@lists.php.net to get a copy of this message
Your problem lies in your while loop. You'll need to assign the various values to the arrays you will use. Since you aren't using parent and location we can exclude those. Also, it isn't necessary (from what you've given us) to use menuid. This is what you should have: > $db->setFetchMode(DB_FETCHMODE_ASSOC); > $result = $db->query('select * from menu where parent = NULL'); > > while ($row = $result->fetchRow()) { > > $display_name[] = $row['display_name']; > $link[] = $row['link']; > } > > $smarty->assign("display_name",$display_name); > $smarty->assign("link",$link); And your template: > <table border="5" cellpadding="0" cellspacing="0" > style="border-collapse: > collapse" width="100%" id="AutoNumber1" bgcolor=gray> > <tr> > <td width="100%" bgcolor=yellow><CENTER><B>MAIN > MENU</B></CENTER></td> > </tr> > <tr> > <td width="100%"> > > {section name=menu loop=$link} > <a href="{$link[menu]}">{$display_name[menu]}</a><br> > {/section} > </td> > </tr> > </table> > -----Original Message----- > From: Jarrod Lash [mailto:jay_rod20@yahoo.com] > Sent: Saturday, August 17, 2002 4:53 PM > To: smarty-general@lists.php.net > Subject: [SMARTY] Smarty PHP Question > > > I am trying to create a generated menu from a database to a > smarty template > and I am having problems. Can somebody shed some light for me? > > ================================================================== > ========== > =========== > I have this in my php file > $db->setFetchMode(DB_FETCHMODE_ASSOC); > $result = $db->query('select * from menu where parent = NULL'); > > while ($row = $result->fetchRow()) { > > $menuid = $row['menuid']; > $display_name = $row['display_name']; > $link = $row['link']; > $parent = $row['parent']; > $location = $row['location']; > } > > $smarty->assign("display_name",?); > $smarty->assign("link",?); > > ================================================================== > ========== > =========== > > and this in my template file > <table border="5" cellpadding="0" cellspacing="0" > style="border-collapse: > collapse" width="100%" id="AutoNumber1" bgcolor=gray> > <tr> > <td width="100%" bgcolor=yellow><CENTER><B>MAIN > MENU</B></CENTER></td> > </tr> > <tr> > <td width="100%"> > > {section name=menu loop=$menuid} > <a href="{$link[menu]}">{$display_name[menu]}</a><br> > {/section} > </td> > </tr> > </table> > ================================================================== > ========== > =========== > What I cant figure out is how to move the data from the database to the > template. I think I should have some kind of array variable > where the ? is > in the php file. Also should menuid in the smarty loop be the number of > rows I returned from the database? > > Thanks, > Jarrod Lash > > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > >

« previous php.smarty.general (#5735) next »