HTML/PHP Selecting A Value From Dropdown Menu And Retrieving The Associated Row And Output All The Data From That Row
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
Solution 1:
Found it!:
if(isset($_POST['select1']))
{
$select = $_POST['select1'];
$street_select = mysql_query("SELECT street FROM table WHERE name = '" .&select. "'");
$street = mysql_fetch_array($street_select);
$resul_street = $street['street'];
}
Now I can do this for every value in each column that is asked via the dropdown menu!
Solution 2:
You can not change a state of any loaded dropdown or text as it is.
You must use jQuery/Ajax here.
When you select on Dropdown value it will than trigger Ajax/jQuery and call another page where your select query will run and return value, which you can display in textbox using jQuery.
<select name = 'select1' onchange='return get_street()'>
<option name='test1'>test1</option>
<input type="text" name ="street" id="street" value="" />
<script>
function get_street()
{
var selected_val = $('option:selected', this).val();
$.ajax({ //ajax call
type: "POST", //method == POST
url: "street.php", //url to be called
data: "name="+selected_val, //data to be send
success: function(data){
$('#street').val(data); // here we will set a value of text box
}
});
}
</script>
And your street.php will look like
<?php
$name = $_POST['name'];
$res = mysql_query("select street from table where name = '".$name."'");
$row = mysql_fetch_assoc($res);
return $row['street']; // this will return a name of street
?>
Few things you need to make sure is
give appropriate path of your file in ajax
give id to your text input and same should be in ajax success
you must connect database in your
street.php
Post a Comment for "HTML/PHP Selecting A Value From Dropdown Menu And Retrieving The Associated Row And Output All The Data From That Row"