PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 5th, 2004, 08:24 AM
sean2004 sean2004 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 11 sean2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 5th, 2004, 08:47 PM
eddynazrul eddynazrul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: 192.168.1.4
Posts: 21 eddynazrul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
while($rowTmp = mysql_fetch_array($rsTmp,MYSQL_BOTH)) { ?>
<option><?=$rowTmp[1]?></option>
<?php } ?>
change to

Quote:
while($rowTmp = mysql_fetch_array($rsTmp,MYSQL_ASSOC)) {
<option><?=$rowTmp[0]?></option>
}
?>
change the $rowTmp[1] to $rowTmp[0].

Because in array, the element start with 0..

Hope it's help..

Reply With Quote
  #3  
Old October 6th, 2004, 03:23 PM
sean2004 sean2004 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 11 sean2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old October 6th, 2004, 08:47 PM
eddynazrul eddynazrul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: 192.168.1.4
Posts: 21 eddynazrul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
while($rowTmp = mysql_fetch_array($rsTmp,MYSQL_ASSOC)) {
echo "<option value='$rowTmp[0]'>$rowTmp[0]</option>\n";
}

Reply With Quote
  #5  
Old October 6th, 2004, 10:54 PM
sean2004 sean2004 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 11 sean2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
Originally Posted by eddynazrul
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..

Reply With Quote
  #6  
Old October 6th, 2004, 11:00 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
make sure your query is correct... try outputting it and pasting it into the MySQL console directly.

Reply With Quote
  #7  
Old October 7th, 2004, 08:46 AM
sean2004 sean2004 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 11 sean2004 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My query is correct I ran the query on the db...it gives me expected results.

Thanks,
Sean

Quote:
Originally Posted by MadCowDzz
make sure your query is correct... try outputting it and pasting it into the MySQL console directly.

Reply With Quote
  #8  
Old October 8th, 2004, 09:58 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 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?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > How to Populate 2 drop down lists from 2 Dioff Tables a MySQL DB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT