bahattab
24-01-2008, 10:28 AM
populate a select box using PHP
I want to populate a few drop down boxes using PHP.
Just loop thru the result using the array and print them .
you also need :
<option value="something">Something</option>
<?php
$link = mysql_connect("localhost", "root", "password") or die("Could not connect: " . mysql_error());
mysql_select_db('db', $link) or die (mysql_error());
$query = "SELECT last_name FROM main_author order by last_name";
$result = mysql_query($query) or die("Couldnt' execute query.");
$num = mysql_numrows($result);
?>
<html>
<body>
<form name="test" id="test" method="post">
<select value="" size="1" name="test2">
<option>all</option>
<?
$i=0; while ($i<$num) {
$row = mysql_fetch_assoc($result);
echo "<option>$row['last_name']</option>";
$i++; }
mysql_close();
?>
</select>
</body>
</html>
http://www.daniweb.com/forums/thread53586.html
I want to populate a few drop down boxes using PHP.
Just loop thru the result using the array and print them .
you also need :
<option value="something">Something</option>
<?php
$link = mysql_connect("localhost", "root", "password") or die("Could not connect: " . mysql_error());
mysql_select_db('db', $link) or die (mysql_error());
$query = "SELECT last_name FROM main_author order by last_name";
$result = mysql_query($query) or die("Couldnt' execute query.");
$num = mysql_numrows($result);
?>
<html>
<body>
<form name="test" id="test" method="post">
<select value="" size="1" name="test2">
<option>all</option>
<?
$i=0; while ($i<$num) {
$row = mysql_fetch_assoc($result);
echo "<option>$row['last_name']</option>";
$i++; }
mysql_close();
?>
</select>
</body>
</html>
http://www.daniweb.com/forums/thread53586.html