...

View Full Version : drop down list box using data from MySQL



jd2003
02-09-2006, 03:10 PM
Hi
I've been trying to create a drop down list box using data from MySQL table. Mysql table is "ihs" and the field to be listed is "Bloom_Name", can someone tell me what's wrong with the code below and if possible tell me how to fix it.
Thank JD


<?PHP
mysql_connect("localhost", "xxx_xx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx_xxx") or die(mysql_error());
$query="SELECT Bloom_Name FROM ihs";
$result = mysql_query ($query);
echo "<select name=ihs value=''>Bloom_Name</option>";
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[name]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>

Kal
02-09-2006, 03:20 PM
hi, i had the same problem a few weeks ago, but i managed to sort it out, here is what i used.

<?php

require ('database.php');//connection to database

$query = "select scriptname from weblink.script_summary where scriptname='$scriptname'";

$result = mysql_query ($query) or die (mysql_error());

echo "<td><b>Please Select A SCRIPT:</b></td> <td><SELECT name=\"scriptname\">";

if (mysql_num_rows($result)>0)

{

while($row=mysql_fetch_array($result))

{

echo "<option value=\"$row[scriptname]\">$row[scriptname]</option>";

}

}

echo "</SELECT></td>";

?>

hope this helps.

degsy
02-09-2006, 03:41 PM
<?php
mysql_connect("localhost", "xxx_xx", "xxxx") or die(mysql_error());
mysql_select_db("xxxx_xxx") or die(mysql_error());
$query="SELECT Bloom_Name FROM ihs";
$result = mysql_query($query);

echo '<select name="ihs">';
while($nt=mysql_fetch_array($result)){ //Array or records stored in $nt
echo '<option value="' . $nt['id'] . '">' . $nt['name'] . '</option>';
/* Option values are added by looping through the array */
}
echo '</select>'; // Closing of list box
?>


try that or post your error messages

jd2003
02-09-2006, 04:12 PM
Hi
I've tried your code, but all I get is an empty drop menu.

degsy
02-09-2006, 04:17 PM
$query="SELECT Bloom_Name FROM ihs";


You need to select the fields from the table


$query="SELECT id, name, FROM ihs";


or


$query="SELECT * FROM ihs";


or depending on your database setup


$query="SELECT id, name, FROM Bloom_Name";

jd2003
02-09-2006, 05:12 PM
Hi
I'm new at this, I guess you figure that out.
below is mysql database.

LOCK TABLES `ihs` WRITE;
INSERT INTO `ihs` (`id`, `Bloom_Name`, `Pod_Parent`,

what I want to list on the drop menu is Bloom_Name what would the id be?
can you please write me the code
Thank you so much

jd2003
02-09-2006, 05:28 PM
Thank you so much, I got it running ok.

jd2003
02-09-2006, 05:42 PM
How can I add on change command on the php script?

<select name="select"onChange=" Hybridiser.value=this.options[this.selectedIndex].text"
size="1">

<?php
mysql_connect("localhost", "xxxx_xx", "xxx") or die(mysql_error());
mysql_select_db("xxxx_xxx") or die(mysql_error());
$query="SELECT Bloom_Name FROM ihs";
$result = mysql_query($query);

echo '<select name="ihs">';
while($nt=mysql_fetch_array($result)){ //Array or records stored in $nt
echo '<option value="' . $nt['id'] . '">' . $nt['Bloom_Name'] . '</option>';
/* Option values are added by looping through the array */
}
echo '</select>'; // Closing of list box
?>

degsy
02-10-2006, 03:53 PM
onchange="this.form.submit()"



<?php
mysql_connect("localhost", "xxxx_xx", "xxx") or die(mysql_error());
mysql_select_db("xxxx_xxx") or die(mysql_error());
$query="SELECT Bloom_Name FROM ihs";
$result = mysql_query($query);

echo '<select name="ihs" onchange="this.form.submit()">';
while($nt=mysql_fetch_array($result)){ //Array or records stored in $nt
echo '<option value="' . $nt['id'] . '">' . $nt['Bloom_Name'] . '</option>';
/* Option values are added by looping through the array */
}
echo '</select>'; // Closing of list box
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum