Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » PHP

Can't use LIKE in IF() ...

 
Jump to:  
 
Mo
PostPosted: 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
PostPosted: 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
PostPosted: 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
PostPosted: 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
PostPosted: 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
PostPosted: 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
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

wyposażenie domu Rapidshare opisy na gg kalkulator kredytowy city