views:

77

answers:

1
$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_query("SELECT * FROM Members WHERE Members.pid = '$temp'") or   die(mysql_error());
A: 

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.

thecoshman
I tried that but it didn't work. THanks thought.
ranzy