Jump to content

Quick Lesson!


herghost

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.