Its a bit hard to express what I want to do but let me give it a shot.
First of all I have a database with a table. One of the columns from that table I will be showing in a select dropdown menu in HTML, to be more precise: this outputs the column 'name' in the dropbown menu:
<?php
$query = mysql_query("SELECT name from table");
echo "<select name='select1'>";
while ($row = mysql_fetch_array($query))
{
echo "<option value'" . $row['name'] ."'>" . $row['name] . "</option>;
}
echo "</select>";
?>
Then when a value is selected in that dropdown, that value needs to be saved in a variable.
if (isset($_POST['button']))
{
$select = $_POST['select1'];
}
As last bit, the value in variable $select
needs to be used to make a SELECT
query. I want to use that variable in the SELECT
statement to look for the corresponding row (in the same table) that is related to the value in the dropdown menu and pick a column and output that value to a textbox or checkbox, depending on as what the value needs to be outputted.
Example:
TABLE
id - name - street - number - ...
row 1: 0 - test1 - teststreet1 - 1 - ...
row 2: 1 - test2 - teststreet2 - 2 - ...
row 3: 2 - test3 - tesstreett3 - 3 - ...
1) I select test2
from the dropdown menu (dropdown menu is filled with the column name from database)
2) test2 is saved as a variable in $name
3) select query searches for value of street column where $name = test2
SELECT street from table where ?
row 2: 1 - test2 - tesstreett2 - 2 - ...
So I want teststreet2 from street to be outputted in a textbox
<input type='text' value='?'>
I need help with the select query or how to call this.
Thanks in advance and taking time to read this!
Kind Regards