Re: [SMARTY] Smarty PHP Question

From: Date: Sun, 18 Aug 2002 22:20:43 +0000
Subject: Re: [SMARTY] Smarty PHP Question
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5743@lists.php.net to get a copy of this message
Thanks for your help Rod!! But there is still a problem.. I have debbugging on for this script and the debbugger is not shows the values of display_name and link as being passed to smarty. Can you assign a array variable by just using its name with smarty. I saw in the examples that came with smarty: $smarty->assign("option_values", array("NY","NE","KS","IA","OK","TX")); can you do this? php/ $states[]=$row['display_name']; template/ $smarty->assign("option_values", $states); "Rod Kreisler" <rod@23net.net> wrote in message news:JNEGKNDJGBKLBDGPOPFOMEDADAAA.rod@23net.net... > 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 (#5743) next »