PDA

View Full Version : database output and <select> box?


Murtific
07-29-2011, 05:36 PM
Trying to put my database output in a <select></select> box. Any ideas how to do it in the template?

I can have the var in php in either an array or in a single variable with all the data in it.

kh99
07-29-2011, 05:48 PM
With the data in an array you should be able to use the vb:each tag, like the example at the end of this article: https://vborg.vbsupport.ru/showthread.php?t=221560 (you can also search your templates for vb:each and find other examples).

Murtific
07-29-2011, 06:39 PM
$chan = mysql_query("SELECT * FROM channels ORDER BY chan ASC", $connection);
while ($list = mysql_fetch_array($chan))
{
$var1 = $list['chan1'];
}

$templater-register('var1', $var1);



<vb:each from="list" value="chan">
<td><select name="cGID" size="1"><option value="{vb:raw list.chan}">{vb:raw list.chan}</option></select></td>
</vb:each>


Not sure if i'm doing it right.I want it to list everything that's in that array in the drop down menu

kh99
07-29-2011, 06:46 PM
I haven't actually used vb:each before, but I think you'd want this:

<td><select name="cGID" size="1">
<vb:each from="var1" value="chan">
<option value="{vb:raw chan}">{vb:raw chan}</option>
</vb:each>
</select></td>



Of course as an alternative, you could do this:

$menu = '<select name="cGID" size="1">';
$chan = mysql_query("SELECT * FROM channels ORDER BY chan ASC", $connection);
while ($list = mysql_fetch_array($chan))
$menu .= '<option value="' . $list['chan1'] . '">' . $list['chan1'] . '</option>';
$menu .= '</select>';

$templater-register('menu', $menu);



<td>{vb:raw menu}</td>

Murtific
07-30-2011, 12:46 AM
$chan = mysql_query("SELECT * FROM channels ORDER BY chan ASC", $connection);
while ($list = mysql_fetch_array($chan))
{
$chanList .= $list['gid']."<br />";
$chanGid .= $list['chan']."<br />";
$chanAcc .= $list['access']."<br />";
$zlist.= "<option value='".$list['gid']."'>".$list['gid']."</option>";
}

then..

$templater->register('zlist',$zlist);

then in the template..

<select name="derp" size="2">{vb:raw zlist}</select>