|  | Can't use LIKE in IF() ... |  | |
| | | Mo |  |
| Posted: Fri Jun 13, 2008 10:54 pm Post subject: Can't use LIKE in IF() ... |  |
so what do I use? In my report, I want to assign a value to a var if the item came from a specific area in our inventory. If the location begins with "WIP", then assign a value of "true".
The $row is from a MySQL_fetch_assoc() in a WHILE statement. I tried: if($dtlRow["loc"] LIKE "WIP%" ) { $brokered=true; } but got a syntax error. Apparently, I'm barking up the wrong tree, and LIKE is not the right way to do this.
I've got my PHP manual ready, but just can't find what I need to look up.
TIA, ~Mo |
| |
| | | Jerry Stuckle |  |
| Posted: Fri Jun 13, 2008 10:54 pm Post subject: Re: Can't use LIKE in IF() ... |  |
Mo wrote:
| Quote: | so what do I use? In my report, I want to assign a value to a var if the item came from a specific area in our inventory. If the location begins with "WIP", then assign a value of "true".
The $row is from a MySQL_fetch_assoc() in a WHILE statement. I tried: if($dtlRow["loc"] LIKE "WIP%" ) { $brokered=true; } but got a syntax error. Apparently, I'm barking up the wrong tree, and LIKE is not the right way to do this.
I've got my PHP manual ready, but just can't find what I need to look up.
TIA, ~Mo
|
LIKE is a SQL construct, not a PHP one. You need to use PHP operators or functions, like ==, strcmp, or a host of others.
-- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| |
| | | Hendri Kurniawan |  |
| Posted: Fri Jun 13, 2008 11:18 pm Post subject: Re: Can't use LIKE in IF() ... |  |
Mo wrote:
| Quote: | so what do I use? In my report, I want to assign a value to a var if the item came from a specific area in our inventory. If the location begins with "WIP", then assign a value of "true".
The $row is from a MySQL_fetch_assoc() in a WHILE statement. I tried: if($dtlRow["loc"] LIKE "WIP%" ) { $brokered=true; } but got a syntax error. Apparently, I'm barking up the wrong tree, and LIKE is not the right way to do this.
I've got my PHP manual ready, but just can't find what I need to look up.
TIA, ~Mo
|
Pick your method... look it up .... - preg_match - substr - strpos
Hendri Kurniawan |
| |
| | | sheldonlg |  |
| Posted: Sat Jun 14, 2008 8:02 am Post subject: Re: Can't use LIKE in IF() ... |  |
Mo wrote:
| Quote: | so what do I use? In my report, I want to assign a value to a var if the item came from a specific area in our inventory. If the location begins with "WIP", then assign a value of "true".
The $row is from a MySQL_fetch_assoc() in a WHILE statement. I tried: if($dtlRow["loc"] LIKE "WIP%" ) { $brokered=true; } but got a syntax error. Apparently, I'm barking up the wrong tree, and LIKE is not the right way to do this.
I've got my PHP manual ready, but just can't find what I need to look up.
TIA, ~Mo
|
SQL: ===== $sql = "SELECT stuff FROM table WHERE loc LIKE 'WIP%'";
Then do the query and check if you get any rows back.
PHP: ==== Check the first three letters of the entries of the array you get from your sql query.
I think doing it in SQL is much easier. |
| |
| | | C. (http://symcbean.blogs |  |
| Posted: Sat Jun 14, 2008 10:20 am Post subject: Re: Can't use LIKE in IF() ... |  |
| |  | |
On Jun 14, 11:02 am, sheldonlg <sheldonlg> wrote:
| Quote: | Mo wrote: so what do I use? In my report, I want to assign a value to a var if the item came from a specific area in our inventory. If the location begins with "WIP", then assign a value of "true".
The $row is from a MySQL_fetch_assoc() in a WHILE statement. I tried: if($dtlRow["loc"] LIKE "WIP%" ) { $brokered=true; } but got a syntax error. Apparently, I'm barking up the wrong tree, and LIKE is not the right way to do this.
I've got my PHP manual ready, but just can't find what I need to look up.
TIA, ~Mo
SQL: ===== $sql = "SELECT stuff FROM table WHERE loc LIKE 'WIP%'";
Then do the query and check if you get any rows back.
PHP: ==== Check the first three letters of the entries of the array you get from your sql query.
I think doing it in SQL is much easier.
|
As a general rule, if it can be done in SQL then it will be faster and more efficient to do it there than in PHP.
Certainly **any** filtering of the results should be done in SQL - of course it may be that a more complete dataset is required and different procesing attached to records of different type (but it might be better to create a column in the result set with a calculated type then do a == operation instead of strpos / preg_match etc)
C. |
| |
| | | Mo |  |
| Posted: Mon Jun 16, 2008 5:11 pm Post subject: Re: Can't use LIKE in IF() ... |  |
| |  | |
On Jun 14, 3:20 am, "C. (http://symcbean.blogspot.com/)" <colin.mckin...@gmail.com> wrote:
| Quote: | On Jun 14, 11:02 am, sheldonlg <sheldonlg> wrote:
Mo wrote: so what do I use? In my report, I want to assign a value to a var if the item came from a specific area in our inventory. If the location begins with "WIP", then assign a value of "true".
The $row is from a MySQL_fetch_assoc() in a WHILE statement. I tried: if($dtlRow["loc"] LIKE "WIP%" ) { $brokered=true; } but got a syntax error. Apparently, I'm barking up the wrong tree, and LIKE is not the right way to do this.
I've got my PHP manual ready, but just can't find what I need to look up.
TIA, ~Mo
SQL: ===== $sql = "SELECT stuff FROM table WHERE loc LIKE 'WIP%'";
Then do the query and check if you get any rows back.
PHP: ==== Check the first three letters of the entries of the array you get from your sql query.
I think doing it in SQL is much easier.
As a general rule, if it can be done in SQL then it will be faster and more efficient to do it there than in PHP.
Certainly **any** filtering of the results should be done in SQL - of course it may be that a more complete dataset is required and different procesing attached to records of different type (but it might be better to create a column in the result set with a calculated type then do a == operation instead of strpos / preg_match etc)
C.
|
Thanks to all for the input and direction. It is very helpful and greatly appreciated.
I do need the complete dataset with different processing for whether this criteria is met or not.
You've given me plenty of stuff to look up. I'm certain that I will now be able to get it going.
Thanks-a-bunch! ~Mo |
| |
|
|