Forum Moderators: coopster

Message Too Old, No Replies

drop-down list

drop-down list

         

photocroatia

8:20 am on Jan 3, 2005 (gmt 0)

10+ Year Member



Hi All,

Again me with a question, I managed to work out how to write a script to select values from my Database to make a drop-down list (based on an example I found)

-----------------------------------------------

$db = mysql_pconnect($dbhost,$dbuser,$dbpass);

mysql_select_db("$dbname",$db);

$result = mysql_query("SELECT val FROM my_table");
echo "<select name='accounts_list'>\n";
while($row=mysql_fetch_array($result))
{
echo "<option name='".$row['val']."'>".$row['val']."</option>\n";
}
echo "</select>\n";

-------------------------------------------------

The drop-down works but I have a few questions:

When someone selects a value in what variable is it stored, I tried echoing a few variable but cant work out where the selected option/value is stored.

I need the value to pass to another php script.

I need to add another drop-down list it will be based on the same column and table, what variables do I need to change to the original to make it work for the second dropdown list.

Is it possible to setup like a default value. considering the drop-down list is based on a table.

And my final question, I have the two drop-down list, the person selects from both , how do I add a query button.

Thank you for your help.

orion_rus

8:35 am on Jan 3, 2005 (gmt 0)

10+ Year Member



In this form u didn't need a name=''".$row.."'
u need a value="row['val'] and if u didn't use a multiple select(as i see) selected value will be stored in a name variable of select

U should change this:


while($row=mysql_fetch_array($result))
{
echo "<option name='".$row['val']."'>".$row['val']."</option>\n";
}

to this:

while($row=mysql_fetch_array($result))
{
echo "<option value='".$row['val']."'>".$row['val']."</option>\n";
}

Good luck to you

photocroatia

8:47 am on Jan 3, 2005 (gmt 0)

10+ Year Member



Thank you, but that didn't work, now nothing appears in my drop-down list.

I do have one other other question:

If I change the query to:

$result = mysql_query("SELECT val,val2 FROM my_table");

I want peopel to see the value val but I need to pass the value from val2 to my othere php script.

I hope I have exaplined myself clear, its a bit confusing.

Thank you.