Sending query result to a combo box

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
okee
Forum Newbie
Posts: 5
Joined: Thu Jan 16, 2003 4:48 pm

Sending query result to a combo box

Post by okee »

I was wondering if it is possible to run a query on a table and then have the results returned to a combo box for a user to select.

What I want to do is when a user enters information about a house on a form they have a combo box which they can click on and select a development name if the house is part of that development.

So the combo box would list all the developments and when the user selects one and submits the form, the id of the development would be added to a field in the houses table.

Any code guiding me in the right direction would be much appreciated.

Thanks

okee
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

this is how you set default data of a select element:

Code: Select all

<?php

// some data:
$arrWithData = Array(Array('val' => 12, 'textval' => 'twelve'),Array('val' => 12, 'textval' => 'twelve'));
$options = '':

foreach ($arrWithData as $Data){
    $options .= '<option value="' . $Data['val'] . '">' . $Data['textval'] . '</option>';
}

?>
<html>
    <form>
    <select name="selectelement">
        <?php echo $options ?>
    </select>
    </form>
</html>
Post Reply