Page 1 of 1

Display table fields in a dropdown

Posted: Wed Jul 26, 2006 9:58 am
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

Posted: Wed Jul 26, 2006 10:02 am
by feyd
getting the fields, would be a DESCRIBE query, not a SELECT.

Posted: Wed Jul 26, 2006 10:16 am
by reecec
o sorry i copied it from the wrong code thanks i know what to do know


thanks

Posted: Wed Jul 26, 2006 11:27 am
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

Posted: Wed Jul 26, 2006 1:41 pm
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>

<?

}

?>

Posted: Thu Aug 03, 2006 4:06 pm
by reecec
thanks for your help i have sorted it now

reece