|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 > 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 ================== |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 Pick your method... look it up .... - preg_match - substr - strpos Hendri Kurniawan |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Jun 14, 3:20 am, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.com> wrote: > 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 ful 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 |
|
![]() |
| Outils de la discussion | |
|
|