Forum Moderators: coopster
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.
U should change this:
while($row=mysql_fetch_array($result))
{
echo "<option name='".$row['val']."'>".$row['val']."</option>\n";
}
while($row=mysql_fetch_array($result))
{
echo "<option value='".$row['val']."'>".$row['val']."</option>\n";
}
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.