A search question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

A search question

Post by micknc »

I have written a search query with good results but now I need to add a new parameter to it and I am getting no where. I am brand new so this is probably something very easy I am overlooking.

Here is what I have:
SELECT * FROM SOHEAD WHERE upper($field)='$find' AND STATUS='P' ORDER BY SO_NO DESC

That is working great.

Now I need to add another variable to the status. I need to return all entries that =$find and that have a status of p or v. I have tired about every combination but I am stuck:

This returns only staus=p
SELECT * FROM SOHEAD WHERE upper($field)='$find' AND STATUS='P' OR 'V' ORDER BY SO_NO DESC

This returns an error:
SELECT * FROM SOHEAD WHERE upper($field)='$find' AND STATUS='P' OR upper($field)='$find' AND STATUS= 'V' ORDER BY SO_NO DESC

This returns correctly on status=p but returns all status=v
SELECT * FROM SOHEAD WHERE upper($field)='$find' AND STATUS='P' OR STATUS='V' ORDER BY SO_NO DESC

Is there something easy I am missing?
Thanks
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: A search question

Post by JAM »

Perhaps try different approaches;

Code: Select all

SELECT * FROM SOHEAD WHERE UPPER($field)='$find' AND STATUS IN('P','V') ORDER BY SO_NO DESCSELECT * FROM SOHEAD WHERE UPPER($field)='$find' AND (STATUS='P' OR STATUS='V') ORDER BY SO_NO DESC
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: A search question

Post by micknc »

Yes, I tried the first one and it worked perfectly.

Thanks. I am learning slowly but surely.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: A search question

Post by califdon »

micknc wrote:Yes, I tried the first one and it worked perfectly.

Thanks. I am learning slowly but surely.
That's the only way! :teach:
Post Reply