<?php $separator = "WHERE "; $sql_query = "SELECT * FROM table_name "; if(isset($_POST['select1'])) // Or maybe if($_POST['select1'] != "")) { $sql_query .= $separator; $sql_query .= "col1 = '{$_POST['select1']}' "; $separator = "AND "; } if(isset($_POST['select2'])) { $sql_query .= $separator; $sql_query .= "col2 = '{$_POST['select2']}' "; $separator = "AND "; } if(isset($_POST['select3'])) { $sql_query .= $separator; $sql_query .= "col3 = '{$_POST['select3']}' "; $separator = "AND "; }
run_sql_query_here(...) ?> Regards Joakim Andersson > -----Original Message----- > From: César Aracena [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, July 10, 2002 12:50 PM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: RE: [PHP] Re: Wildcard > > > Ok. Maybe I didn't express myself well (must be the 3-4 days awake ;) > > No, I don't have an example on-line 'couse this is something > I'll start > doing in a few days or hours. Well, just what it will probably be the > search options at: http://www.icaam.com.ar/proyects/os-seek/ which I > posted a few hours ago. > > What I want, is to let the visitor search for an OS developer by > WORK-AROUND and/or LANGUAGE and/or LOCATION and have just ONE static > query to handle all this. The thing is that if I make the query like > this: > > SELECT * FROM table_name WHERE col1 = $elect1 AND col2 = $select2 AND > col3 = $select3 > > I think maybe the script will go nuts if no option was selected > (remember the and/or?). So I figured out that maybe by > telling HTML that > the default value of each SELECT box is % (or any kind of > wildcard) the > query might run as predicted. Does this makes ant sense now? > > Please go to the site I've mentioned before and afterwards > (if have the > time and will) go back a couple of dozens post back and read the post > called *MORE WORK FOR US I HOPE* so you have a more clear > understanding > of what my need will be. > > Thanks, C. > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, July 10, 2002 7:27 AM > > To: [EMAIL PROTECTED] > > Subject: [PHP] Re: Wildcard > > > > why put in your query you want to look for an value .. if they don't > want > > to > > look for it ?.. > > > > > > vins writes: > > > > > Shit..... > > > Doesn't really make sense > > > Sorry... I probably don't understand > > > > > > do you have an online example. > > > > > > > > > "César aracena" <[EMAIL PROTECTED]> wrote in message > > > 000101c227fb$74eed940$68ed0dd1@gateway">news:000101c227fb$74eed940$68ed0dd1@gateway... > > > Hi all. > > > > > > I'm trying to figure out how to do a search trough a > MySQL db using > LIKE > > > or = but the thing is that I have 3 select boxes from where to > choose > > > the search terms. Can I use something like a wildcard instead of > making > > > several IF statements like this? > > > > > > SELECT * FROM table_name WHERE col1 = value1 AND col2 = value2 AND > col3 > > > = % > > > > > > % goes for an unselected select box (default value = %) > in case the > user > > > doesn't want to make an *advanced* search, so it fetches all rows > which > > > does contains values 1 & 2. > > > > > > Thanks, > > > > > > <mailto:[EMAIL PROTECTED]> Cesar Aracena > > > CE / MCSE+I > > > Neuquen, Argentina > > > +54.299.6356688 > > > +54.299.4466621 > > > > > > > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php