Jump to content

Creating a filter


brown2005

Recommended Posts

SELECT * 
FROM table1,table2,table3,table4,table5 
WHERE table1_f = table2_id
AND table1_g = table3_id  
AND table4_p = table1_id
AND table5 _m = table4_id
ORDER BY RAND() 
LIMIT 1

 

Right, Now What I want to do, is have a filter form, which posts to the above, and if:

 

$filter1 = "";

 

it wont be include in the above code

 

$filter1 = "word";

 

then i want to include

 

AND table3_n = '$filter1';

 

in the above code

 

thanks in advance.

Link to comment
Share on other sites


$word = $_GET['word'] ? $_GET['word'] : "";

if($word == ""){$crap = "";}else{	$crap = "AND table3_n = $word'';}					


SELECT * 
FROM table1,table2,table3,table4,table5 
WHERE table1_f = table2_id
AND table1_g = table3_id  
AND table4_p = table1_id
AND table5 _m = table4_id
$crap
ORDER BY RAND() 
LIMIT 1 

 

this is what i mean above. so if there is no word it shows all results, but if there is a word, it will only show results with that word.

 

is this code correct?

 

Thanks in advance

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.