Hello, I'm new on this forum
I have a small question on connecting mysql / php
I would like to display the contained of many different table from the same database in multiple dropdown boxs with a connection between them (example: choose a selection in the first box and it changes the contained the second box)
Read data from a mysql database in dropdown box
Moderator: General Moderators
Re: Read data from a mysql database in dropdown box
Best bet would be to implement an AJAX solution using onchange events in each of the select lists.
Re: Read data from a mysql database in dropdown box
For displaying database items I use this code :
The first $nt is the item to store in the database, the second one is the item to be displayed.
In this code the ID will be stored en displayed. But when you use : The ID will be stored, but the name will be displayed.
Code: Select all
mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("pop_security") or die(mysql_error());
$query="SELECT id FROM pop";
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
$result = mysql_query ($query);
echo "<select name=delete value=''>Student Name</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[id]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box ?>
In this code the ID will be stored en displayed. But when you use :
Code: Select all
echo "<option value=$nt[id]>$nt[id]</option>";-
jonessamentha
- Forum Newbie
- Posts: 1
- Joined: Sat Mar 31, 2012 10:10 pm
Re: Read data from a mysql database in dropdown box
hmmmm how can it possible i can't believe.