Jump to content

Table Fields in a dropdown


reecec

Recommended Posts

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.
[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.

Archived

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

×
×
  • Create New...

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.