Newb needing the Results from 3 fields matching from query.

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
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Newb needing the Results from 3 fields matching from query.

Post by ridshack »

Could someone give me advice on how I would query the database and present only the results that matched my criteria? Example:

Database: Office
Table: AForm
Feild1: TechName (Steve)
Feild2: DateRecordEntered (Today)
Field3: ClientName (Brown Inc.)
MoreFileds…..

I want to find only the records that match all three search criteria Steve, Today, and Brown.

Code: Select all

SELECT TechName, DateRocord, ClientName, MoreFields... FROM AForm
 WHERE TechName='$name', DateRecord='$date', ClientName='$client'
Thanks for your help!
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Try using OR instead of the comma's... WHERE this=that OR that=theother
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Newb needing the Results from 3 fields matching from que

Post by Zoxive »

ridshack wrote:Could someone give me advice on how I would query the database and present only the results that matched my criteria? Example:

Database: Office
Table: AForm
Feild1: TechName (Steve)
Feild2: DateRecordEntered (Today)
Field3: ClientName (Brown Inc.)
MoreFileds…..

I want to find only the records that match all three search criteria Steve, Today, and Brown.

Code: Select all

SELECT TechName, DateRocord, ClientName, MoreFields... FROM AForm
 WHERE TechName='$name', DateRecord='$date', ClientName='$client'
Thanks for your help!
I don't quite understand.. Whats wrong with what you have?

Code: Select all

$name = 'Steve';
$client = 'Brown Inc.';
$today = date("m-d-Y");// Whatever your format is..

Code: Select all

SELECT * From `AForm` WHERE `TechName`='$name' AND `DateRecord`='$today' AND `ClientName`='$client'
-NSF
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Post by ridshack »

How obvious now that I see the answer… I need to change the commas to AND

Also I see that OR can be used in different scenarios.

Thanks Everyone.
Post Reply