search query question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
olm75
Forum Newbie
Posts: 16
Joined: Fri Aug 05, 2005 8:05 pm

search query question

Post by olm75 »

so if the fields in my form are:
txt_Venuename
txt_Areacode
opt_Venuetype
opt_Agegroup
opt_Musictype

and the db columns are:
venuename
areacode
venuetype
agegroup
musictype

it should look like this:
Code:

Code: Select all

$sql = 'SELECT * FROM `some_db` WHERE '; 
$flag=0; 

if( $_REQUEST['text1'] ) { 
$sql .= "field1 LIKE $_REQUEST[text1] "; 
$flag+=1; 
} 

if( $_REQUEST['text2'] ) { 
$sql .= ($flag >=1 )?"AND field2 LIKE $_REQUEST[text1] " : "field2 LIKE $_REQUEST[text1] "; 
$flag+=1; 
} 

if( $_REQUEST['op1'] ) { 
$sql .= ($flag >=1 )?"AND field3 LIKE $_REQUEST[op1] " : "field2 LIKE $_REQUEST[op1] "; 
$flag+=1; 
} 

if( $_REQUEST['op2'] ) { 
$sql .= ($flag >=1 )?"AND field4 LIKE $_REQUEST[op2] " : "field3 LIKE $_REQUEST[op2] " : "field2 LIKE $_REQUEST[op2] "; 
$flag+=1; 
} 

if( $_REQUEST['op3'] ) { 
$sql .= ($flag >=1 )?"AND field5 LIKE $_REQUEST[op3] " : "field4 LIKE $_REQUEST[op3] " : "field3 LIKE $_REQUEST[op3] " : "field2 LIKE $_REQUEST[op3] "; 
$flag+=1; 
} 

//........... 

$sql .=";"; 

//execute

now what do i replace $flag with.......
and then this should give the user any combonation af search no matter what field they choose.......to narrow down their search....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why, oh why pray tell did you post this in PHPDeveloper.org?


Moved to PHP - Code. :roll:
Post Reply