using two databases and using info to produce friends list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kedora19
Forum Commoner
Posts: 34
Joined: Tue Apr 07, 2009 10:05 am

using two databases and using info to produce friends list

Post by kedora19 »

so i have a friends table and a status table. what would be the best way to use both tables and get info from both of them to only show the status of your friends.

ex. on facebook you can see peoples "status" BUT only your friends "status" not some random guy,

thats what i'm trying to get at
here's my starting code (which shows EVERY status)

Code: Select all

 
<?php
                            include '../login/dbc.php';
  
                            //first open connection to your database
 
                            $takeuser = mysql_query("SELECT * FROM userstatus");
                            $takeuser2 = mysql_query("SELECT * FROM users");
   
                            while ($row=mysql_fetch_array($takeuser)) { //Taking the result set
                            echo '<font color="#ff8538">' . $row['username'] . '</font>'. ': ' . $row['message'] . '<br />';
                            echo $row['time'] . $row['date'] . '<br /><br />'  ;
                            } //closing the loop
   
 
                            mysql_close($link); //and then we close connection
?>
 
i do have start session at the top of my page (so i can use the SESSION variable)

but from here on I don't really know what to do, I know i'll probably have to use the "else" statment but either then that, don't know what to do.


Any help would be appreciated,
thanks in advance, kedora19
Last edited by Benjamin on Sat May 09, 2009 11:02 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: using two databases and using info to produce friends list

Post by Christopher »

You should look in to the SQL JOIN statement. Using JOIN will allow you to pull the records of multiple related tables at one time. JOIN is really the "relation" part of relational databases.
(#10850)
Post Reply