Click to See Complete Forum and Search --> : Populating a drop-down menu...


scottyrob
04-05-2006, 04:53 AM
Hi how can i populate a drop down menu from my DB.. here is what i have...
DB Name = Camp
Fields = Attend
Location
FromtTo
Leadership...

I would like the Drop Down menu to show 'Attend'... When the user selects attend i would like the details 'Attend, Location, Fromto and Leadership' displayed on the page (Relating to the 'Attend' Chosen from the drop down menu).. Thanks!..

jogol
04-05-2006, 05:16 AM
<?php
do {
?>
<option class="option" value="<?php echo "$row[0]\n"?>">
<?php echo "$row[0]\n"?>
</option>
<?php
}
while ($row = mysql_fetch_row($result));
$rows = mysql_num_rows($result);
if($rows > 0) {
mysql_data_seek($result, 0);
}
?>
dunno if it is the best method to do it but it works fine for me here.

intrivious
04-05-2006, 12:47 PM
Just another way to look at it:

<select name='list_name'>
<?php
// $result = some database query result
while ($row = mysql_fetch_row($result)) {
echo "<option class='option' value='".$row[0]."'>".$row[0]."\n";
}
?>
</select>


But, if you want something more dynamic, where when you type something in, on the letter you type in the list adjusts automatically, then we need to go another route. If so, let us know...

scottyrob
04-07-2006, 02:24 AM
HI.. i have this code...

<?
require 'plate_bg/db_connect.php';

echo "<link rel='stylesheet' type='text/css' href='css/main.css' />";

$query = "SELECT * FROM danish";
$result = mysql_query($query) or die("Error: " . mysql_error() . " with query $query");

if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

while ($row = mysql_fetch_array($result)) {
echo "<select name='list_name'>";
echo "<option class='option' value='".$row[Production_Date]."'>".$row[Production_Date]."\n";
echo "</select>";

}
mysql_free_result($result);
?>

But if you go to http://www.loddonexplorers.co.uk/Erik/info.php you'll see my prolem... how do i make it into one drop-down menu instead of many?

rch10007
04-07-2006, 02:37 AM
If I understand your question, then your problem is that you need to move the select statement outside you fetch statement:

echo "<select name='list_name'>";
while ($row = mysql_fetch_array($result)) {
echo "<option class='option' value='".$row[Production_Date]."'>".$row[Production_Date]."\n";
}
echo "</select>";


this way, all the results from the query are in one selection menu - is that what you are trying to get?

scottyrob
04-07-2006, 02:47 AM
Yup that worked! Thanks very much!