herghost Posted September 22, 2009 Share Posted September 22, 2009 Hi all, i have this from a php book: $query = 'SELECT username, first_name, last_name, city, state, email, postcode FROM users u JOIN users_info i ON u.user_id = i.user_id WHERE username = "' . mysql_real_escape_string($_SESSION['username'], $conn) . '"'; $result = mysql_query($query, $conn) or die(mysql_error($conn)); $row = mysql_fetch_array($result); extract($row); mysql_free_result($result); mysql_close($conn); ?> Now I get what most of it means, however what does this mean? users u JOIN users_info i ON u.user_id = i.user_id I get it is selecting the tables, but whats all the i's and u.'s? How would I add a further table users _credits? Many Thanks Link to comment https://forums.phpfreaks.com/topic/175102-quick-lesson/ Share on other sites More sharing options...
trq Posted September 22, 2009 Share Posted September 22, 2009 u is an alias for the users table while i is an alias for the users_info table. Link to comment https://forums.phpfreaks.com/topic/175102-quick-lesson/#findComment-922887 Share on other sites More sharing options...
monkeytooth Posted September 22, 2009 Share Posted September 22, 2009 u is a row on table1 and i is a row on table2 .. with the join your looking for something that matches specific criteria. What it is doing is searching 2 tables at once with one query. In the example provided your looking user and user_info.. they both share the same ID on both tables so in this case your looking for "users" id, and then searching for the user_info with that id.. or something to that effect. I'm not one for giving real good descriptions but I hope that gives you the jist of it Link to comment https://forums.phpfreaks.com/topic/175102-quick-lesson/#findComment-922888 Share on other sites More sharing options...
herghost Posted September 22, 2009 Author Share Posted September 22, 2009 Thanks, I think I get It! What I am trying to do is probably quite simple, I just want to display the users credits! Basically in the table users_credits there are two fields, user_id & credits. Whats the best way of doing this? Link to comment https://forums.phpfreaks.com/topic/175102-quick-lesson/#findComment-922893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.