Jump to content

Looping & query help


Matt G

Recommended Posts

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!

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.