Afficher un message
Vieux 14/06/2008, 12h20   #5
C. (http://symcbean.blogspot.com/)
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can't use LIKE in IF() ...

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.
  Réponse avec citation
 
Page generated in 0,04864 seconds with 9 queries