473,574 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Mo
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_ass oc() 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
Jun 27 '08 #1
5 1144
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_ass oc() 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.
js*******@attgl obal.net
=============== ===

Jun 27 '08 #2
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_ass oc() 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
Jun 27 '08 #3
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_ass oc() 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.
Jun 27 '08 #4
On Jun 14, 11:02 am, sheldonlg <sheldonlgwrote :
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_ass oc() 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.
Jun 27 '08 #5
Mo
On Jun 14, 3:20 am, "C. (http://symcbean.blogsp ot.com/)"
<colin.mckin... @gmail.comwrote :
On Jun 14, 11:02 am, sheldonlg <sheldonlgwrote :
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_ass oc() 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
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
12957
by: Adams-Blake Co. | last post by:
This may be OT a bit, so maybe someone can point me in the right direction. I want to test a script that sends out an e-mail. I want to test it locally on my Mandrake Linux 8.2 box. It runs OK on my host (pair.com) but I have to upload it each time I want to test it. Is there something I need to do in order to test locally? Do I have...
3
4034
by: lawrence | last post by:
I haven't been able to reach www.php.net for days. Most of the rest of the web is working for me, though I've bad trouble reaching any English sites. Anyone else having trouble?
6
2458
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what happens if one of those objects, when it is created, takes a reference to the object that contains it? Do bad things happen? class McShow {
1
2138
by: Mr Mint | last post by:
Hi all, I have a page named register.php, which is a form for collecting user data. As an example: - I have the fields Name, Surname, email. - In the <form> tag I have action ="" - The page register.php has a condition if (isset($_POST)) { include('register2.php'); }
5
2647
by: The Biscuit Eater | last post by:
Greetings from a second day newbie to php. I think I have figured out a way to explode a field in a csv file (like 11-08-03) and implode it as 031108 and then compare it to the current date(ymd) to display data after the current date. What I would like to now do is use the 11 and display Nov. Can anybody help or point me in the right...
9
3660
by: NotGiven | last post by:
I have a web page where certain pages have to be opened in a certain order and should only be available when the user openes them in HTTPS. They are all forms and the form action sends you to the next https:// page but you can also take the S out of https:// and it opens also. That's what I need to avoid as well as making certain they got...
1
21434
by: Krista | last post by:
Hi, this is my problem. I have two php files such as a.php, b.php a.php : <?php require("b.php"); if($_GET == "") { MainFrame(); } else if ($_GET == "Receiving")
4
3252
by: berehneh | last post by:
i have a site in a host with adomain i can run php with .php files but i can 't use php in .htm file. how can i do this
0
4657
by: Phil Powell | last post by:
<?php class FileRemoval { var $fileNameArray, $isRemoved, $errorMsg = ''; function FileRemoval() { // CONSTRUCTOR $this->fileNameArray = array(); $this->isRemoved = 0; }
14
3874
by: NotGiven | last post by:
I am guessing I would hold a variable of when it's opened, then in the script that runs when the page is offloaded, I coudl calcualte it. How do you store a time variable? How do you calculate the amount of time (seconds) based on two timestamps? Thanks for your help and/or links to articles on the subject!
0
7801
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3739
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1055
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.