Reputation: 31
So I'm trying to select the username from the users table BASED ON if they are in a gang.
Vars used.:
$member_gang = mysql_fetch_assoc(mysql_query("SELECT level,gangid,rating FROM user_stats WHERE id = '" . $_SESSION['user']['id'] . "'"));
$gang_info = mysql_fetch_assoc(mysql_query("SELECT * FROM gangs WHERE id = '".$member_gang['gangid']."'"));
And here's when I want to display it.
$getmembers = mysql_fetch_assoc(mysql_query("SELECT * FROM user_stats WHERE gangid = '" . $gang_info['gangid'] . "'"));
$displaymembers = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE id = '" . $getmembers['id'] . "'"));
echo 'One Member of this gang is: <b>'.$displaymembers['username'].' </b>:)';
(I do have db connection etc..) It's not echoing the username?!
EDIT: I am not that good at PHP, i don't understand prepared statements?
Upvotes: 0
Views: 82
Reputation: 1872
$gang_info['id']
not
$gang_info['gangid']
because you wrote above
"SELECT * FROM gangs WHERE id...."
and not
"SELECT * FROM gangs WHERE gangid..."
?
And why did you set the Ids in ' '? Are they strings? When not, change them to integer, thats a better solution for primary keys.
Upvotes: 1