Click to See Complete Forum and Search --> : drop down menus in php


minus18
07-31-2001, 11:29 AM
Can anyone tell me why this puts a list of entries in my frame, not in my table?

<td><select name= userid size = 3>
<option value =>".dropDown()."
</select>
</td>

/************************************************** ***************************/
// function dropDown() //
/************************************************** ***************************/

function dropDown()
{
mysql_connect("localhost", "root", "*****");

$result = mysql_db_query("db", "select user_id from staff");
while($row = @mysql_fetch_array($result))
{
echo "<option value = ".$row[0]."><br> ".$row[0];
}
}

I've had a poke around on the net and can't get any scripts to work.

Cheers or Tshuss as we say here in Bavaria

EyesWideOpen
07-31-2001, 01:19 PM
Edited because my info wasn't correct.

[ 31 July 2001: Message edited by: EyesWideOpen ]

Stuka
07-31-2001, 01:55 PM
Actually, it looks to me like you're dropDown() function is printing out your <option> tags - and you've put an <option> tag in front of that - which could be screwing it up (I'm no expert, but I've dabbled). To do something similar, I used code like this:<form action="cfgpg3.php">
<select name="acd" size="3">
<?php
$query = 'SELECT SYS_NAME FROM SYS_NAMES WHERE OEM = '."\"$oem\"";
$result = mysql_query($query);
if (!$result) die($query);
while ($row = mysql_fetch_row($result)){
print("<OPTION>".$row[0]."\n");
}
?>
</select>And it works as expected.

EyesWideOpen
07-31-2001, 02:11 PM
It looks as if Stuka is right. In case you still want to use the function the following should work (untested):


<td><select name= userid size = 3>
<?php
dropDown();
?>
</select>
</td>

/************************************************** ***************************/
// function dropDown() //
/************************************************** ***************************/

function dropDown()
{
mysql_connect("localhost", "root", "*****");

$result = mysql_db_query("db", "select user_id from staff");
while($row = @mysql_fetch_array($result))
{
echo "<OPTION>" .$row[0]. "\n";
}
}

jcrowe
08-01-2001, 08:21 AM
To make the functio even more portable you could send the query as a paramitter of the function. Then it could be used for more than one drop down.

minus18
08-01-2001, 09:55 AM
Thanks.

It was the print within print problem.

Cheers Stuka. Actully my supe fixed it while I was out at a German lesson.