Dear all

I want to populate a few drop down boxes using PHP. However i have tried many examples i found from the web but the select box does not get any values. Below i have one example i have tried.

**********************************************
<?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)
{$authors=mysql_result($result,$i,"last_name");
echo "<option>$authors</option>";
$++; }
mysql_close(); ?>
</select>
</body>
</html>
********************************************

any suggestions would be more than appreciated

Many thnx

Cheers

Dear all

<?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>
********************************************

Try that and see if it works
Just loop thru the result using the array and print them

StatiX

This article has been dead for over six months. Start a new discussion instead.