Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL Field Names into PHP Dropdown Menu


MySQL Field Names into PHP Dropdown Menu

Reply
  #1 (permalink)  
Old 06-09-05, 12:26 PM
KaraJ KaraJ is offline
New Member
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL Field Names into PHP Dropdown Menu

Hello,

Does anyone know if it is possible to pull the field names from a MySQL database into a PHP-generated dropdown menu? I know how to pull data from the database into a dropdown menu and then return results based on the user's choice, but I cannot figure out how (or if it is possible) to pull the actual field names into the dropdown menu. Any help would be very much appreciated!
Reply With Quote
  #2 (permalink)  
Old 06-09-05, 01:34 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #3 (permalink)  
Old 06-09-05, 01:40 PM
alabaster_lynch alabaster_lynch is offline
Wannabe Coder
 
Join Date: Mar 2005
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by KaraJ
Hello,

Does anyone know if it is possible to pull the field names from a MySQL database into a PHP-generated dropdown menu? I know how to pull data from the database into a dropdown menu and then return results based on the user's choice, but I cannot figure out how (or if it is possible) to pull the actual field names into the dropdown menu. Any help would be very much appreciated!
Yes, this is very possible...I would do something like this
PHP Code:

<?php

mysql_connect
('localhost''user''password');
mysql_select_db('database');
$result mysql_query('select * from table');
?>
<select name="selectname">
<?php
$i 
0;
while (
$i mysql_num_fields($result)){
  
$fieldname mysql_field_name($result$i);
  echo 
'<option value="'.$fieldname.'">'.$fieldname.'</option>';
  
$i++;
}
?>
</select>
hope this helps....Jose
Reply With Quote
  #4 (permalink)  
Old 06-13-05, 10:01 AM
KaraJ KaraJ is offline
New Member
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I just got a chance to try your suggestions and they worked great. Thanks, guys!

Kara
Reply With Quote
  #5 (permalink)  
Old 06-14-05, 09:28 AM
KaraJ KaraJ is offline
New Member
 
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I have another question related to this. Hopefully someone can help me with it. Does anyone know how to choose specific field names from a database if you don't know what they are ahead of time? For instance, I have a database with concentrations of various chemical elements that were taken in different years. To avoid a lot of extra rows of data, I gave each element its own field. But, not all elements were tested in each year. I would like people to be able to choose the year they are interested in (there is a year field in the database as well) and, based on that, return a list of elements for which there is data. Then, they can pick only the elements they are interested in from that year and get the actual data. The only sticking point right now is that I don't know how to extract just the element fields that have data in them for the year that was chosen. Help, anyone?

Kara
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP & Mysql Dropdown with OnSelect edgar PHP 3 10-22-04 07:07 AM
JS Menu Swapper with PHP and mySQL ? xgab PHP 3 06-23-04 08:20 AM
Dropdown menu + php + mysql = one lost newbie PsYch0 PHP 2 04-29-04 01:40 PM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 03:31 AM


All times are GMT -5. The time now is 06:50 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.