PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Can't use LIKE in IF() ...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Can't use LIKE in IF() ...

Réponse
 
LinkBack Outils de la discussion
Vieux 13/06/2008, 23h54   #1
Mo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 14/06/2008, 01h50   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can't use LIKE in IF() ...

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
==================

  Réponse avec citation
Vieux 14/06/2008, 02h18   #3
Hendri Kurniawan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can't use LIKE in IF() ...

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
  Réponse avec citation
Vieux 14/06/2008, 11h02   #4
sheldonlg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can't use LIKE in IF() ...

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.
  Réponse avec citation
Vieux 14/06/2008, 11h20   #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
Vieux 16/06/2008, 18h11   #6
Mo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can't use LIKE in IF() ...

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h04.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11920 seconds with 14 queries