Scavenger
06-11-2010, 11:19 PM
Hello everyone!
This is my first post, I've been reading the forums and learning php & mysql for some time. I'm stuck with a doubt, I hope and appreciate if you can help me.
I'm running a web site using a database. To retrieve user's info I use:
$UsersQuery = mysql_query("SELECT * FROM users WHERE id=$id");
To get their usernames, registered date, etc. And I print that info with:
$user = mysql_fetch_assoc($UsersQuery)
$user['registered], etc
That works great, but when I want to retrieve who invited the user (invited_by, its an INT)
I tried something like $user['invited_by'], of course it will retrieve the INT of the inviter user (user id), but how can I make it to print the username of that inviter?
I can do something like
$invited_by = mysql_query("SELECT username FROM users WHERE id=$user[invited_by]");
$inviter = mysql_fetch_array($invited_by);
And I print it like:
$inviter['username']
But I'm using another query, I don't know if that's right because I already stored all the user's info in $user. Is there an easier way to do it?
Thanks for your help/time and excuse my noob question. :)
This is my first post, I've been reading the forums and learning php & mysql for some time. I'm stuck with a doubt, I hope and appreciate if you can help me.
I'm running a web site using a database. To retrieve user's info I use:
$UsersQuery = mysql_query("SELECT * FROM users WHERE id=$id");
To get their usernames, registered date, etc. And I print that info with:
$user = mysql_fetch_assoc($UsersQuery)
$user['registered], etc
That works great, but when I want to retrieve who invited the user (invited_by, its an INT)
I tried something like $user['invited_by'], of course it will retrieve the INT of the inviter user (user id), but how can I make it to print the username of that inviter?
I can do something like
$invited_by = mysql_query("SELECT username FROM users WHERE id=$user[invited_by]");
$inviter = mysql_fetch_array($invited_by);
And I print it like:
$inviter['username']
But I'm using another query, I don't know if that's right because I already stored all the user's info in $user. Is there an easier way to do it?
Thanks for your help/time and excuse my noob question. :)