I am a nyophyte to PHP, and I've seen this answered so many different ways that it is confusing.
I have a combobox that is dynamically populated from a MySQL table ACTIVE in a database AIRCRAFT. Based on the selected AIRCRAFTREGISTRATION value from the combobox, I want to find and display the value from a column in the same table labeled USEABLESEATS for the record with that AIRCRAFTREGISTRATION.

Here is the code combobox:

<select name="AssignAircraft" size="1" id="AssignAircraft" style="position:absolute;" <?php
$mysqli = NEW MySQLi('hostname','User','Password','AIRCRAFT');

$resultSet = $mysqli->query("SELECT AIRCRAFTREGISTRATION FROM ACTIVE");
?>

<SELECT NAME="ACTIVE">
<?php
while($rows = $resultSet->fetch_assoc())
{
    $acreg = $rows['AIRCRAFTREGISTRATION'];
    echo "<option value='$acreg'>$acreg</option>";  
}
?>
</SELECT>>

Hi there!

I'm so sorry! I had thought I had answered this earlier but I guess the post didn't go through for some reason, so here I am posting again.

I see that the code you've provided loops through all the list of aircraftregistration choices for the select box. Are you saying you now want to create a new script that uses those values?

You will need to wrap your select box within a form which posts to a new PHP page designed to show the results.

You can use $_POST['ACTIVE'] to retrieve the variable that has the selected value of the form.

Then, you can write a SQL query such as:

$selection = $_POST['ACTIVE'];
// [ ... Code that MySQL escapes $selection value to prevent injection attacks ...]    
$result = $mysqli->query("SELECT USEABLESEATS FROM ACTIVE WHERE AIRCRAFTREGISTRATION = '$selection'"):

Does that make sense?

$resultSet = $mysqli->query("SELECT `AIRCRAFTREGISTRATION`,`USEABLESEATS` FROM ACTIVE");

<?php
while($rows = $resultSet->fetch_assoc())
{
    $acreg = $rows['AIRCRAFTREGISTRATION'];
    echo "<option value='$acreg'>$acreg - Seats:{$rows['USEABLESEATS']}</option>";  
}
?>

Looks like what you are asking.

Is AIRCRAFTREGISTRATION the unique key for that table? You usually refer to unique ID refs in a drop down and use that programmatically.

The value='$acreg' should be the unique ID of the aircraft to use in the code then the text in the option <option>USER FRIENDLY</option> is something the user will recognise or is useful to help him pick the right aircraft.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.