|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Retrieving data for Drop down list.
Hi everyone,
I am writing a PHP/HTML form that retrieve some data from MySQL database. However, I have problem on the drop down list. I want to retrieve two set of table: The first set of data will be used as the data of the dropdown list. The second data (one string) is the inputted data from users. I would like to compare the user inputted data and the dropdown list data. If the entry is the same, then "selected" that entry for the drop downlist. So that users know what the current selection is. I can retrieved the list for dropdown. However, I have problem to compare and "selected" the current entry. Can anyone help me on this issue? Thank you very much in advance. Regards, Vincent --- Here is my sloppy code: <Html> <head> <title>Detail testing </title></head> <body> <select name="site"> <?php $db = mysql_connect("localhost", "root", "p3pp3r"); mysql_select_db("equestdb", $db); $db2 = mysql_connect("localhost", "root", "p3pp3r"); mysql_select_db("equestdb", $db2); //get the id $id= $_GET["id"]; //for listing the user inputted data. $rs_detail = mysql_query("Select * from eqbase where eq_id= '$id'", $db); // using for dropdown list data $rs_sitelist = mysql_query("Select * from site_id order by site_id", $db1); if($mysitelist=mysql_fetch_array($rs_sitelist)){ // list dropdown do{ $site_v = $mysitelist["site_val"]; if ($myblist=mysql_fetch_array($rs_detail)) { $site_n = $myblist["site"]; if ($site_n == $site_v ){ // try to compare userinputted data. $theone="selected"; printf("<option value='%s' %s >%s</option>", $mysitelist["site_val"], $theone, $mysitelist["site_nam"]); // if the same, print selected on that option list } } printf("%s",$mysitelist["site_val"]); printf("<option value='%s' %s >%s</option>", $mysitelist["site_val"], $theone, $mysitelist["site_nam"]); } while ($mysitelist = mysql_fetch_array($rs_sitelist)); } else { echo "No Records!!"; } ?> </select> </body> </Html> |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Retrieving data for Drop down list. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|