开发者

unknown column in where clause

$result = mysql_query("SELECT * FROM Volunteers WHERE Volunteers.eventID = " . $var);

$sql = mysql_query("SELECT * FROM Members WHERE Members.pid = " . $temp);

I am also doing or die(mysql_error()) at the end of both statements if that matter. My problem is that the first statement executes perfectly but in that table I store an attribute called pid. So the second statement is supposed to take that and return the row where it equals that pid so I can get the name. I get an error that says unknown column in 'a2' in 'where clause' where a2 the pid attribute returned from the first statement. Thanks for any help!

EDIT: Figured out what was wrong. Had to write the code like this:

$sql = mysql_qu开发者_StackOverflow中文版ery("SELECT * FROM Members WHERE Members.pid = '$temp'") or   die(mysql_error());


I think I see what you are trying to do, you can do this in one query, by JOIN-ing the tables together. the SQL query should be something like

SELECT Members.* FROM Members INNER JOIN Volunteers ON Volunteers.eventID=Members.pid WHERE Volunteers.eventID=" . $var

Check out This for a basic introduction to SQL joins.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜