help with php/sql

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
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

help with php/sql

Post by Monopoly »

Well I'd like to select values from fields that are in rows with other 2 values

Code:

$sql="SELECT * FROM forum_question WHERE id='$id', forums_id='$forums_id'";
$result=mysql_query($sql);

After WHERE I used two conditions (matching id and forums_id)

But I get an error

How can I solve the problem?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: help with php/sql

Post by aceconcepts »

You need to replace the comma with AND:

Replace:

Code: Select all

 
$sql="SELECT * FROM forum_question WHERE id='$id', forums_id='$forums_id'";
 
With:

Code: Select all

 
$sql="SELECT * FROM forum_question WHERE id='$id' AND forums_id='$forums_id'";
 
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: help with php/sql

Post by superdezign »

... Duplicate thread?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: help with php/sql

Post by aceconcepts »

naughty naughty - tut tut tut
Post Reply