My tables:
users
CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, `first_name` varchar(32) NOT NULL, `last_name` varchar(32) NOT NULL, `email` varchar(1024) NOT NULL, `active` int(11) NOT NULL DEFAULT '0', `email_code` varchar(32) NOT NULL, `avatar` varchar(55) NOT NULL, `type` int(1) NOT NULL DEFAULT '0', `protected` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;feeds
CREATE TABLE IF NOT EXISTS `feeds` ( `id` int(6) NOT NULL AUTO_INCREMENT, `user_id` int(6) NOT NULL, `username` varchar(32) NOT NULL, `body` text NOT NULL, `date` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;and buddys
CREATE TABLE IF NOT EXISTS `buddys` ( `id` int(6) NOT NULL AUTO_INCREMENT, `user_one` int(6) NOT NULL, `user_two` int(6) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;What I'm using to fetch the users data and feeds etc
$my_id = $_SESSION['user_id'];
if ($getquery = mysql_query("SELECT * FROM feeds f
INNER JOIN users u ON u.user_id = f.user_id
WHERE u.user_id = '$my_id' OR u.user_id IN
(SELECT b.user_one OR b.user_two FROM buddys b
WHERE b.user_one OR b.user_two = '$my_id')")){
// resultset processing goes here
while ($rows = mysql_fetch_assoc($getquery)){
$id = $rows['id'];
$user_id = $rows['user_id'];
$username = $rows['username'];
$body = $rows['body'];
$date = $rows['date'];
$dellink = "| <a href=\"http://localhost/vibeate/wigets/deletepost.php?id=" . $id . "\" style='color: grey;text-decoration:none;'>Delete</a>";
?>
<h2><a href="users/<?php echo $username; ?>"><?php echo $username; ?></a></h2>
<p><?php echo $body; ?></p><br />
Posted on <?php echo $date; ?> <?php if ($user_id == $user_data['user_id'] || is_admin($user_data['user_id']) === true){
echo $dellink;
}
?>
<br /><hr width="500px">
<?php
}
} else {
echo mysql_error();
}
if (empty($id)){
echo '<h3>There\'s no posts to show...Be the first to post</h3>';
}