Jump to content


Photo

Table Fields in a dropdown


  • Please log in to reply
4 replies to this topic

#1 reecec

reecec
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 29 July 2006 - 11:07 PM

hi please can someone help me I need a script that will get the table fields and put them in a drop down

would this be done using DESCRIBE

thanks reece

#2 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 29 July 2006 - 11:13 PM

Here's basically how you'd do it:
<?php
// Connect to database

$query = "SELECT id, name FROM fields";
$result = mysql_query($query);
echo '<select name="fields">';
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    echo '<option value="'.$row[0].'">'.$row[1].'</option>';
}
echo '</select>';
?>

Of course, replace the values you're working with to make it work.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#3 reecec

reecec
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 30 July 2006 - 12:15 AM

thanks for your reply

sorry i may not have explained it well i mean the column names not the row values

thanks reece

#4 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 30 July 2006 - 12:20 AM

The column names? I dont know if you can do that...you have to select things BASED on the column names.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 July 2006 - 01:07 AM

describe provides ALL the information - http://www.webdevelo...sql_tables.php3

get the column (field) names only - see the snippet by jamesl at si-usa dot com at http://ca.php.net/ma...-field-name.php

You should be able to do what you want based on that snippet and a little coding.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users