faqts : Computers : Databases : MySQL : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 16 people (19%) answered Yes
Recently 0 of 10 people (0%) answered Yes

Entry

how do i extract elements from a database into a Select Form Field?

Mar 20th, 2002 01:37
Stefan Immel, Jan-Borge Landro,


Here's a little example in php.
<?php
$sock = mysql_connect("localhost");
$dbh = mysql_select_db("mydb",$sock);
$tab = mysql_query("select * from mytable",$sock);
$numrow = mysql_num_rows($tab);
for($i = 0; $i < $numrow; $i++)
{
   $row = mysql_fetch_row($tab);
   echo("<option value=\"$row[0]\">$row[1]</option>");
}
?>