Re: [SMARTY] smarty, php, and mysql

From: Date: Sun, 14 Apr 2002 08:46:54 +0000
Subject: Re: [SMARTY] smarty, php, and mysql
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-3699@lists.php.net to get a copy of this message
Blue Presley wrote:
If there is someone out getting to work, please provide me with the following: 1. a sample, fully working, php script pulling a few rows from a mysql database and assinging to a variable that smarty will recognize. 2. a .TPL file (just the template code here, of course) that creates an html <selection> box using the array elements from the .php script. I'm sure if I had a working example from which to work, this would not be this frustrating. Thanks in advance for your help. Blue Here's some (untested) sample code that might help:
###################### // ...mysql connection / query code here... $row = mysql_fetch_array($result); $name = $row['user_name']; $email = $row['user_email']; // Stuff to describe your selection box $selection_options = array('angry', 'happy', 'hungry', 'sleepy'); $selection_descriptions = array('Very Angry', 'Happy, thanks', 'Need food!', 'Half asleep...'); $selected = 'happy'; // Smarty code $smarty = new Smarty; $smarty->assign( 'name' => $name, 'email' => $email, 'selection_options' => $selection_options, 'selection_descriptions' => $selections_descriptions, 'selected' => $selected ); $smarty->display('template.tpl'); ###################### And in template.tpl: ###################### <p>Name: {$name}</p> <p>Email: {$email}</p> How are you today? <select name="mood"> {html_options values=$section_options output=$section_values selected=$selected} </select> ###################### Hope that helps, Simon Willison

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