Jump to content

Archived

This topic is now archived and is closed to further replies.

reecec

Table Fields in a dropdown

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
thanks for your reply

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

thanks reece

Share this post


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

Share this post


Link to post
Share on other sites
[b]describe[/b] provides ALL the information - http://www.webdevelopersnotes.com/tutorials/sql/mysql_lesson_mysql_tables.php3

get the column (field) names [b]only[/b] - see the snippet by jamesl at si-usa dot com at http://ca.php.net/manual/en/function.mysql-field-name.php

You should be able to do what you want based on that snippet and a little coding.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.