|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
janmartin Smarty Rookie
Joined: 28 Mar 2004 Posts: 7 Location: nearby London, UK
|
Posted: Sun Mar 28, 2004 4:19 pm Post subject: html_options vs. array: Dropdownlist from a 2 column table? |
|
|
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 |
|
janmartin Smarty Rookie
Joined: 28 Mar 2004 Posts: 7 Location: nearby London, UK
|
Posted: Sun Mar 28, 2004 5:00 pm Post subject: found a workaround |
|
|
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 |
|
janmartin Smarty Rookie
Joined: 28 Mar 2004 Posts: 7 Location: nearby London, UK
|
Posted: Sun Mar 28, 2004 6:57 pm Post subject: better workaround |
|
|
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 |
|
|
|
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
|