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
https://forums.phpfreaks.com/topic/226779-creating-a-filter/
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
https://forums.phpfreaks.com/topic/226779-creating-a-filter/#findComment-1170244
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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