Lee Redhead
asked on
Setting SELECTED value of a drop down list that is populated via a database lookup when posting a form back to itself
Hello,
I am fairly new to PHP having come from a .NET background and one thing I am missing is the POSTBACK function of the forms and what that offered.
In essence what I am trying to do is have a user select two values from two drop down lists then use these two values and query the database to return the correct value.
If possible I would prefer to just have the one page and then retain the values that are selected on the page in the DDLs when the final value is displayed.
I know it is possible just to have the form action redirect to another page where I could show the values that have been selected but I would much prefer to keep the user not he one page and just keep the selected values int he DDL like I would have done in .NET.
After a search I have found options on setting the selected value but unless I am missing something with the syntax then these don't seem to be working wight eh way I am populating the menu.
I have attached the code I am using for the population of the DDLs below.
Many thanks.
I am fairly new to PHP having come from a .NET background and one thing I am missing is the POSTBACK function of the forms and what that offered.
In essence what I am trying to do is have a user select two values from two drop down lists then use these two values and query the database to return the correct value.
If possible I would prefer to just have the one page and then retain the values that are selected on the page in the DDLs when the final value is displayed.
I know it is possible just to have the form action redirect to another page where I could show the values that have been selected but I would much prefer to keep the user not he one page and just keep the selected values int he DDL like I would have done in .NET.
After a search I have found options on setting the selected value but unless I am missing something with the syntax then these don't seem to be working wight eh way I am populating the menu.
I have attached the code I am using for the population of the DDLs below.
$conn = dbconn();
$query = "SELECT width, mm, inch FROM tbl_width ORDER by mm ASC" or die("Error in the consult.." . mysqli_error($conn));
$result = $conn->query($query);
$return_height = "";
while ($row = mysqli_fetch_array($result)){
$return_height .= "<option value=\"" . $row['width'] . "\">" . $row['mm'] . " mm ( " . $row['inch'] . " inches )</option>";
}
return $return_height;
Many thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER