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);

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.