Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

html_options vs. array: Dropdownlist from a 2 column table?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
janmartin
Smarty Rookie


Joined: 28 Mar 2004
Posts: 7
Location: nearby London, UK

PostPosted: Sun Mar 28, 2004 4:19 pm    Post subject: html_options vs. array: Dropdownlist from a 2 column table? Reply with quote

Hi,
all I want is a dropdownlist of a 2 column table.

register.php:
<?
require_once 'setup/myauth.php';
$smarty->assign('timezones', $db->getAll("SELECT * FROM timezones"));
$smarty->display('register.tpl');
?>

register.tpl:
...
<select name=timezones>
{html_options options=$timezones }
</select>
...

BUT its not working because the values are not key and value of the timezones array.
Its and array (named timezones) containing 30 arrays (named 0 to 29) containg the data by assoc.

How to make a dropdownlist?

{debug} output:
...
{$timezones} Array (30)
0 => Array (2)
offset => -12
towns => (GMT -12:00 hours) Eniwetok, Kwajalein
1 => Array (2)
offset => -11
towns => (GMT -11:00 hours) Midway Island, Samoa
2 => Array (2)
offset => -10
towns => (GMT -10:00 hours) Hawaii
3 => Array (2)
offset => -9
towns => (GMT -9:00 hours) Alaska
4 => Array (2)
offset => -8
towns => (GMT -8:00 hours) Pacific Time (US & ...
5 => Array (2)
offset => -7
towns => (GMT -7:00 hours) Mountain Time (US &...
...


Last edited by janmartin on Sun Mar 28, 2004 5:09 pm; edited 1 time in total
Back to top
View user's profile Send private message
janmartin
Smarty Rookie


Joined: 28 Mar 2004
Posts: 7
Location: nearby London, UK

PostPosted: Sun Mar 28, 2004 5:00 pm    Post subject: found a workaround Reply with quote

This does the work until there is something more elegant available:
Code:
<select name=timezones>
{section name=counter loop=$timezones}
<option value="{$timezones[counter].offset}">{$timezones[counter].towns}</option>
{/section}
</select>
Back to top
View user's profile Send private message
janmartin
Smarty Rookie


Joined: 28 Mar 2004
Posts: 7
Location: nearby London, UK

PostPosted: Sun Mar 28, 2004 6:57 pm    Post subject: better workaround Reply with quote

Code:
<?
//register.php
require_once 'setup/myauth.php';

$sql = "SELECT offset,towns FROM timezones";
$result = mysql_query($sql);
while($row = mysql_fetch_row($result)) {
$timezones[$row[0]] = $row[1];
}

$smarty->assign('timezones',$timezones);
$smarty->assign('timezones_zero', 0);
$smarty->display('register.tpl');
?>

register.tpl:
...
Timezone
<select name=timezone>
{html_options options=$timezones selected=$timezones_zero}
</select><br>
...
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP