Little problem understandign the WHERE clause

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Little problem understandign the WHERE clause

Post by a94060 »

Hi,im using this query to retrieve all results where the username is equal to $payee and the payed status s N,i think it is because i am not understaind the WHERE clause:

Code: Select all

$sql = "SELECT * FROM coffers WHERE username= $payee AND payed=N";
cansoemone just clear it up for me? i checked out in the manual and could not really udnerstand how to define the WHERE.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

If the variable isn't an integer it needs to be encapsulated in single quotes...

Code: Select all

$sql = "SELECT * FROM `coffers` WHERE `username`='" . $payee . "' AND `payed`='N'";
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok,thanks,ill check that out tommorow.
Post Reply