Re: smarty and db

From: Date: Tue, 03 Aug 2004 20:26:05 +0000
Subject: Re: smarty and db
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-192610@lists.php.net to get a copy of this message
On Tue, 3 Aug 2004 14:21:45 -0500 (EST), Amanda Hemmerich <ahemmeri@indiana.edu> wrote: > Ok, I am starting a new job and learning a new person's code, and trying > to learn Smarty at the same time. > > This question is so basic, but I have no idea where to look for an answer. > > ANyway, I need to change the code so that, when there are no row returned > by the database, a message is displayed saying, "There are no events > scheduled." or what have you. > > Now, the way I would have done this before using smarty would be to check > the number of records, and if there were none, I would display the > message, otherwise, I would loop through and display the results, > > However, I know one of the points of smarty is to keep code out of the > presentation layer, so I don't want to go into the template and add an if > statement in there. > > Any help directing me to an example or whatever would be helpful. > > Here is what is going on right now in the code: > > (in the PHP page) > $events = $db->getAll($sql_events, DB_FETCHMODE_ASSOC); > $tpl->assign("events",$events); > > (in the template page) > {section name=id loop=$events} > <tr> > <td class="event"> > <b>{$events[id].type}</b>: <a class="menulink" > > href="{$url_prefix}/community/events/?id={$events[id].id}">{$events[id].date|date_format:"%B > %e, %Y"}, {$events[id].speaker}</a><br /> > {$events[id].title} > </td> > </tr> > {/section} > My solution to this would be to change the template. IMHO it's a "view" funciton to display something different when there is no data. However, if you're averse to that, I would suggest using a different template. -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.general (#192610) next »