List/menu options from database

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
mastermp2
Forum Newbie
Posts: 2
Joined: Sun Jun 06, 2010 1:50 pm

List/menu options from database

Post by mastermp2 »

Hello

I need help trying to populate 2 list/menu with some database information.

Let's suppose that this is my table:

id brand model
--- ------- --------
1 citroen c1
2 citroen c2
3 citroen c3
4 toyota t1
5 toyota t2
6 volvo v1


I have 2 list/menu. One is the brand menu, which extracts the values in the brand column of the database (using the DISTINCT statement in MySql). So when you click the menu, this options appear:


citroen
toyota
volvo


The code for that menu is something like this:

<select name="menu_marque" id="menu_marque">
<option value="null">select</option>
<?php do { ?>
<?php
print '<option value="'.$row_marque_recordset['marque'].'">'.$row_marque_recordset['marque'].'</option>';
?>
<?php } while ($row_marque_recordset = mysql_fetch_assoc($marque_recordset)); ?>
</select>


Now, I want to do the same for the model menu. The problem is that I don't know how to write in the Sql, that it should take the selected value of the brand menu. I have something like this:

SELECT modele FROM test WHERE marque = 'colname' ORDER BY modele ASC

(where colname is: $_POST['menu_marque']..... Obviously I am not getting the value by a POST method, but I tried changing it to something like:

menu_marque.selectedIndex

but it doesn't work...... Any tips on how can I solve this
Post Reply