Forum Moderators: coopster

Message Too Old, No Replies

PHP script

Query for drop down lists

         

robert43920

6:59 pm on Jun 13, 2010 (gmt 0)

10+ Year Member



Hello i'm looking for a PHP script that will query against a MySQL database from multiple dropdown lists that a user selects from then displaying what needs to be displayed from their selections, any help would be appreciated thanks...

dreamcatcher

9:11 am on Jun 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi robert43920,

This can only be accomplished using Ajax. You`ll find many free code snippets online for chained select options.

dc

Sherif

11:43 pm on Jun 15, 2010 (gmt 0)

10+ Year Member



Hi robert43920,

as "dreamcatcher" said, AJAX is the way to go... it is a method known as Asynchronous JavaScript and XML.

This is basically used when you want to dynamically update the contents of a page without a redirection or refresh...BUT, you must have a page for the MySQL query that you want to return..

For the sql part, generally you can use the GROUPBY command in MySQL to group the part of data that you want.


SELECT Table1 GROUP BY Table1.ColumnName ORDER BY Table1.ColumnName ASC


This will allow you to filter the data based on the different values available in the ColumnName.

For the List Hovever, it could be based on something like this:



<select name="city" id="city">
<option value="">All</option>
<?php
do {
?>
<option value="<?php echo $queryarray['City']?>"><?php echo $queryarray['City']?></option>
<?php
} while ($queryarray = mysql_fetch_assoc($query));
$rows = mysql_num_rows($query);
if($rows > 0) {
mysql_data_seek($query, 0);
$queryarray = mysql_fetch_assoc(query);
}
?>
</select></td>




Good Luck,
Sherif