PHP AJAX Mysql filtering database results

I have a test mysql table with 15 rows, and 4 columns. What I want to be able to do is use a form and filter down the mysql results using ajax requests so when a user invokes a filter they can see the changes in the resulting dataset. I have a demo of what I am talking about at http://marketing.cox7.com. My question / issue is that I can not figure out how to bind the filters together, for example when you visit that page and select segment 1 from the first drop down, you will see the updated results with only segment 1 as a value, I then want to select a key marketing challenge value from the drop down and see only records that both match the segment and key marketing selections. Can you provide any tips and or ideas?

Sean

here is my index.php
[php]


Client Segment: Please Select 1 2 3 4
Key Marketing Challenge: Please Select Awareness-NEW Awareness-MAINTAIN Community
Target Demographic: Please Select Adults 18-34 Adults 18-49 Adults 25-54
<?php $con = mysql_connect('localhost', 'cox7co5_market', 'marketing'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("cox7co5_marketing", $con); $sql="SELECT * FROM packages"; $result = mysql_query($sql); echo "There are ".mysql_num_rows($result). " total un filtered packages available.

"; echo ""; while($row = mysql_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Package Segment KMC Demo
" . $row['Package'] . "" . $row['Segment'] . "" . $row['Kmc'] . "" . $row['Demo'] . "
"; mysql_close($con); ?>

[/php]
here is the getsegment.php file
[php]

<?php $q=$_GET["q"]; $con = mysql_connect('localhost', 'cox7co5_market', 'marketing'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("cox7co5_marketing", $con); $sql="SELECT * FROM packages WHERE Segment = '".$q."'"; $result = mysql_query($sql); echo "There are ".mysql_num_rows($result). " filtered results returned.

"; echo ""; while($row = mysql_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Package Segment KMC Demo
" . $row['Package'] . "" . $row['Segment'] . "" . $row['Kmc'] . "" . $row['Demo'] . "
"; mysql_close($con); ?>

[/php]
here is the getkmc.php file
[php]

<?php $q=$_GET["q"]; // check for your q values, 1 = all, 2 = M, 3 = F $con = mysql_connect('localhost', 'cox7co5_market', 'marketing'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("cox7co5_marketing", $con); $sql="SELECT * FROM packages WHERE Kmc = '".$q."'"; $result = mysql_query($sql); echo "There are ".mysql_num_rows($result). " filtered results returned.

"; echo ""; while($row = mysql_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Package Segment KMC Demo
" . $row['Package'] . "" . $row['Segment'] . "" . $row['Kmc'] . "" . $row['Demo'] . "
"; mysql_close($con); ?>

[/php]

Look up SQL WHERE specifically AND and OR operations should do what your looking for.

Sponsor our Newsletter | Privacy Policy | Terms of Service