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
RE: [PHP] Re: Wildcard
?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
RE: [PHP] Re: Wildcard
Theres no point selecting on a value if they've not specified one. The following code should generate a valid query, assumin that the default value for each value select value is an empty string: $query = SELECT * FROM table_name ; $where_string = WHERE ; $and = ; if ($select1 != ) { $where_string .= $and.col1 = '.addslashes($select1).'; $and = AND ; } if ($select2 != ) { $where_string .= $and.col2 = '.addslashes($select2).'; $and = AND ; } if ($select3 != ) { $where_string .= $and.col3 = '.addslashes($select3).'; $and = AND ; } if ($where_string != WHERE ) { $query .= $where_string; } And then run the query as normal. HTH, Richy == Richard Black Systems Programmer, DataVisibility Ltd - http://www.datavisibility.com Tel: 0141 435 3504 Email: [EMAIL PROTECTED] -Original Message- From: César Aracena [mailto:[EMAIL PROTECTED]] Sent: 10 July 2002 11:50 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
RE: [PHP] Re: Wildcard
Thanks everyone for your attention but still at the 1st step. What I want (not need but want) is to keep my code as short as possible for future referencing from others. Looking at some on-line manuals I found this just now: (^|[^a-zA-Z])foo([^a-zA-Z]|$) which Works if you want to find foo in foo bar, bar foo, bar foo bar, or foo but NOT in foobar or barfoo. I guess that just by taking out the *foo* word between them can make it work for quite a useful wildcard. What do you think pals? C. -Original Message- From: Richard Black [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 8:06 AM To: 'César Aracena' Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Re: Wildcard Theres no point selecting on a value if they've not specified one. The following code should generate a valid query, assumin that the default value for each value select value is an empty string: $query = SELECT * FROM table_name ; $where_string = WHERE ; $and = ; if ($select1 != ) { $where_string .= $and.col1 = '.addslashes($select1).'; $and = AND ; } if ($select2 != ) { $where_string .= $and.col2 = '.addslashes($select2).'; $and = AND ; } if ($select3 != ) { $where_string .= $and.col3 = '.addslashes($select3).'; $and = AND ; } if ($where_string != WHERE ) { $query .= $where_string; } And then run the query as normal. HTH, Richy == Richard Black Systems Programmer, DataVisibility Ltd - http://www.datavisibility.com Tel: 0141 435 3504 Email: [EMAIL PROTECTED] -Original Message- From: César Aracena [mailto:[EMAIL PROTECTED]] Sent: 10 July 2002 11:50 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php