Matt G Posted January 27, 2012 Share Posted January 27, 2012 Hello everyone, Im still new to JS/Ajax/PHP and Im creating a filter(html checkbox form) that will call a single query that will filter unwanted items.. This query contains a INNER JOIN, AND and ON conditions. I have also created a simple javascript loop to scan the form for checked values.. but im having trouble connecting the dots.. Im not certain how to make each checked value trigger individual parts of the query.. Heres what I have: Loop: function sendInfo(form) { var filterList = ""; for( var i =0; i < form.elements.length; i++ ) { if( form.elements[i].type = 'checkbox' ) { if( form.elements[i].checked == true ) { filterList += form.elements[i].value + ','; } } } alert("The filter list is " + filterList); } HTML FORM: <form name="filterForm" id="filterForm"> <input type="checkbox" name="red" value="red" id="red"> RED <input type="checkbox" name="blue" value="blue" id="blue"> BLUE <input type="checkbox" name="green" value="green" id="green"> GREEN <input type="submit" name="submit" value="click" onClick="sendInfo(document.filterForm)"> </form> PHP/Mysql QUERY:(used to filter results) $submitFilter= isset($_POST['submit']); if($submitFilter) { //checks for submitted form //connect to database //select database $filterQuery= mysql_query("SELECT * FROM table_1 INNER JOIN table_2 ON table_1.color_Id=table_2.color_Id WHERE table_2.color_Category <> 'red' AND table_2.color_Type <> 'red' AND table_2.color_Category <> 'blue' AND table_2.color_Type <> 'blue' AND table_2.color_Category <> 'green' AND table_2.color_Type <> 'green' As you can see I have joined two tables and want to exclude any from table_1 where the color is red.. how can I request this action from the loop once a check box has been checked??? like I said im new so if this looks wrong/confusing feel free to be brutal !! I have searched the forums and Iv been close to finding an example/post but nothing solid.. I think I mayb using the wrong terminology/descriptions in my searches to find the correct results bcuz I feel like im circling the block to no end.. PLEASE HELP or POINT ME IN THE RIGHT DIRECTION!!!!! THANKS IN ADVANCE FOLK! Quote Link to comment https://forums.phpfreaks.com/topic/255888-looping-query-help/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.