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 September 19th, 2004, 04:30 PM
Gerald Gerald is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 Gerald User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
problem populating dropdown menu

Hi!!

I am trying to populate my dropdown menu by getting the values
from the database.In this code I am trying to populate the "name" field
from the table "details".I am getting a blank dropdown without any values in it.
Can anybody please help me in this code.


<html>
<body>
<?php
include ("localhostconnection.php");
?>
<select name="id" style="width: 200px;">
<?php
$query = mysql_query("SELECT name FROM details" );
while ($row = mysql_fetch_array($query))
{
$j = mysql_num_fields($query);
for($i=0;$i<$j;$i++)
{
$k = mysql_field_name($query,$i);
$$k = $row[$k];
}
print("<option value=\"$id\">$user</option>\n");
}
?>
</select>
</body>
</html>

Thankyou.

Reply With Quote
  #2  
Old September 19th, 2004, 06:20 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
OK based on what I see here I would highly recommend looking through a few php tutorials. There's loads out there and they will help you understand what parts of this script do.

To give you some help to get you started though the for loop in your code is of no use at all. You just need the while loop with the print statement in it. Something like

// run query

// while (get a result)

// print values

-KM-

Reply With Quote
  #3  
Old September 19th, 2004, 07:10 PM
Gerald Gerald is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 Gerald User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thankyou

Hi !!

I think i was wrong in mentioning the field names and I think we need a pointer for sure
which points to the each item in dropdown list.I didn't understand that.Now i got it.
Anyway Thankyou so.... much

Reply With Quote
  #4  
Old September 20th, 2004, 10:59 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
Where's $id being set/changed?

You could change all that PHP to read:

PHP Code:
 $query mysql_query("SELECT name FROM details" );
while (
$row mysql_fetch_array($query))
{
     
$id++;
     print(
"<option value=\"$id\">".$row['name']."</option>\n");


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > problem populating dropdown menu


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 6 hosted by Hostway
Stay green...Green IT