Re: [SMARTY] html_options questions
| From: | messju mohr | Date: | Thu, 17 Apr 2003 23:11:08 +0000 |
| Subject: | Re: [SMARTY] html_options questions | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9309@lists.php.net to get a copy of this message | ||
On Thu, Apr 17, 2003 at 03:55:45PM -0700, Ryan Allen wrote:
>
> Hi, I'm very confused how html_options works.
>
> I'm getting a bunch of rows from a database. I'm trying to put one
> field as the name of the drop down entry and another field as the id.
> All I can get the drop down box to say is:
>
> Option
> Option
> Option
> Option
> Option
> Option
>
> Here is my code:
>
> index.php:
>
> while ($row= mysql_fetch_object($result)) {
> $data[]=$row;
i think you should do
$data[$row->id] = $row->title;
instead.
this makes $data an associative-array mapping the value of the options
to the title that is to be printed. what you constructed was an array
of objects.
> }
> $sm->assign('data', $data);
>
>
>
> index.tpl:
> <p><font size="5">Select test effort:</font></p>
> <select name=effort>
> {html_options options=$data name=$data->title }
> </select>
remove the "<select>" and "</select>" (it is done by html_options
for you) and do
{html_options options=$data name="effort"}
HTH
messju
> The mySQL table has three fields:
>
> | id | title | versionID |
>
> It's got 6 rows of data, and I'm getting 6 "Options" in the drop down
> box, so I know we are getting the data. How can I display the title and
> not "Option"??? The documentation is not that clear, and does it a
> different way. Thanks!
>
> -- Ryan
>
>
>
> Ryan Allen
> Senior Test Engineer
> F5 NETWORKS
> email: r.allen@f5.com
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php