Jump to content

Help with filtering a query via Drop Downs


mikemcg36

Recommended Posts

Hello,

 

I need help filtering an SQL query based on the combination of drop down menus. I have tried using this code found in another thread but I am still getting all rows selected. Any ideas?? Thank you.

 

Here is my html

<form name="xml.php" method="POST">
            <input type="button" id="showmarkers" value="Show Markers" />  
                <select name="meetingType">
                <option value="All Types" selected="All Types">All Types</option>           
                <option value="fun">fun</option>
                <option value="work">work</option>
                </select>  
                <select name="meetingDay">
                <option value="All Days" selected="All Days">All Days</option>
                <option value="Monday">Monday</option>
                <option value="Tuesday">Tuesday</option>
                <option value="Wednesday">Wednesday</option>
                <option value="Thursday">Thursday</option>
                <option value="Friday">Friday</option>
                <option value="Saturday">Saturday</option>
                <option value="Sunday">Sunday</option>
                </select>  
                <select name="meetingTime">
                <option value="All Times" selected="All Times">All Times</option>
                <option value="Early">Early</option>
                <option value="Noon">Noon</option>
                <option value="Late">Late</option>
                </select>
</form>

 

And the PHP:

$whereClauses = array();
if (! empty($_POST['meetingType'])) $whereClauses[] ="meetingType='".mysql_real_escape_string($_POST['meetingType'])."'";
if (! empty($_POST['meetingDay'])) $whereClauses[] ="meetingDay='".mysql_real_escape_string($_POST['meetingDay'])."'";
if (! empty($_POST['meetingTime'])) $whereClauses[] ="meetingTime='".mysql_real_escape_string($_POST['meetingTime'])."'";
$where = '';
if (count($whereClauses) > 0) { $where = ' WHERE '.implode(' AND ',$whereClauses); }
$resultID = mysql_query("SELECT * FROM meetings".$where);

I have used this with success. jQuery Chained.  Here is an example using it:

 

<?php if($cats):?>
<select id="cat" name="category_id">
	<option value="">Game Genre</option>
	<?php foreach($cats as $cat):?>
	<option value="<?php echo $cat->category_id;?>"><?php echo $cat->category_title; ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>

<?php if($subs):?>
<select id="sub" name="sub_cat_id">
	<option value="">Sub Genre</option>
	<?php foreach($subs as $sub):?>
	<option value="<?php echo $sub->sub_cat_id;?>" class="<?php echo $sub->setting_id;?>"><?php echo $sub->sub_cat_name; ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>	

 

<script type="text/javascript" >
$("#sub").chained("#cat");
</script>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.