|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to Populate 2 drop down lists from 2 Dioff Tables a MySQL DB...Help!!! Pls
Hello!
I am a newbie to PHP-MySQL. I am trying to populate 2 drop down lists from a MySQL DB. First drop down list(Build_Name) has building names and 2nd one has dates(Pickup_Dates) . These r my two tables... CREATE TABLE Buildings ( Bldg_Name varchar(25) NOT NULL default '' PRIMARY KEY, Driver_ID tinyint(2) NOT NULL default '0' ) TYPE=MyISAM; CREATE TABLE order ( Order_ID INT(5) NOT NULL default 101, Bldg_Name varchar(25) NOT NULL default '', Pickup_Date date NOT NULL default '0000-00-00', PRIMARY KEY (Order_ID,Delivery_Date,Bldg_Name) ) TYPE=MyISAM; Pls look the below code... All I see is a small drop down list with NO VALUES in it? why? what's wrong with this code? Also, I have to have 2 drop down lists(one for homes and other for pickup dates from homes & orders tables. once a user chooses lets say home1 from homes drop down list and 10/02/2004 from pickup dates drop down list If a record exists it should display the order. <HTML> <select name="home_name"> <?php include "mysql_data.inc"; //contains db connection string ONLY $strsql = "select Home_Name from homes"; $rsTmp = mysql_query($strsql) or die("Query failed"); while($rowTmp = mysql_fetch_array($rsTmp,MYSQL_BOTH)) { ?> <option><?=$rowTmp[1]?></option> <?php } ?> </select> </HTML> Why is my Drop Down List EMPTY? Thanks, Sean |
|
#2
|
||||
|
||||
|
Quote:
Quote:
Because in array, the element start with 0.. Hope it's help.. |
|
#3
|
|||
|
|||
|
How to Populate drop down menu from MySQL DB Any Help Pls
Hello!
I tried this one tooo... while($rowTmp = mysql_fetch_array($rsTmp,MYSQL_ASSOC)) { <option><?=$rowTmp[0]?></option> } ?> still all I get is an Empty drop down list... Any immediate Help pls...its been a week I am stuck on this one.... Thanks, Pradeep |
|
#4
|
|||
|
|||
|
I'm sorry. I give you the wrong codes.Actually, the option menu was empty because we not echo the <option> and the rest of elements that should print out at the drop menu
Try this.. Quote:
|
|
#5
|
|||
|
|||
|
Hello,
Tried that one too...still drop down list is empty... I still can't believe I am unable to crack this one... Thanks, Sean Quote:
|
|
#6
|
||||
|
||||
|
make sure your query is correct... try outputting it and pasting it into the MySQL console directly.
|
|
#7
|
|||
|
|||
|
My query is correct I ran the query on the db...it gives me expected results.
Thanks, Sean Quote:
|
|
#8
|
||||
|
||||
|
If you're using MYSQL_ASSOC than you need to use the Associated key instead of the index number...
Try the following: Code:
while($rowTmp = mysql_fetch_array($rsTmp,MYSQL_ASSOC)) {
echo "<option value='".$rowTmp['Home_Name']."'>".$rowTmp['Home_Name']."</option>\n";
}
What does your output/HTML look like? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > How to Populate 2 drop down lists from 2 Dioff Tables a MySQL DB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|