Display table fields in a dropdown

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

Display table fields in a dropdown

Post by reecec »

Hi all

how would i make it so that it will display all the fields from the table and put them in a dropdown what is wrong with this

Code: Select all

$result = mysql_query("select * from $url limit 100");

if ($result) {   
?>
Search
<form action="" method="post">
<input name="search" type="text" />
<select name="field"><option><? while (mysql_fetch_field($result)) ?></option></select>
thanks reece
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

getting the fields, would be a DESCRIBE query, not a SELECT.
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

Post by reecec »

o sorry i copied it from the wrong code thanks i know what to do know


thanks
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

Post by reecec »

hi all

shouldnt this work

i get this error
Parse error: parse error, unexpected T_STRING.

it doesnt like having the value in a drop down but will do an echo.

Code: Select all

<?php

$resource = mysql_query("DESCRIBE `profiles`");

while ($data = mysql_fetch_assoc($resource))
{
?>

<elected><option><?  ' .$data['Field'].  ' ?> </option><selected>"

<?

}

?>

thanks reece
klarinetking
Forum Commoner
Posts: 59
Joined: Mon Jul 24, 2006 9:43 am

Post by klarinetking »

Hi,

Try this:

Code: Select all

<?php

$resource = mysql_query("DESCRIBE `profiles`");

while ($data = mysql_fetch_assoc($resource))
{
?>

<elected><option><?php echo $data['Field']; ?> </option><selected>

<?

}

?>
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

Post by reecec »

thanks for your help i have sorted it now

reece
Post Reply