We will understand the process of binding a list box to MySQL by an example. Suppose we have a database "test" having table ex1 which contains columns id,name. We need to bind the name field with the list box. For this we will use the following PHP script:
<?php
$link = mysql_connect("localhost", "root", "root");//set your hostname, username and password
mysql_select_db("test");
$query = "SELECT name FROM ex1";
$result = mysql_query($query);
print "<SELECT name=item>";
while ($line = mysql_fetch_array($result))
{
foreach ($line as $value)
{
print "<OPTION value='$value'";
}
print ">$value</OPTION>";
}
mysql_close($link);
print "";
?>
0 Comment(s)