Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple Design of friends list database
    primarykey
    data
    text
    <p>I have a small issue with making a friendship system database. now I have a table called friends let's say:</p> <p>table friends:</p> <pre><code> you friend approve since _________________________________________________ wetube youtube 1 4-12-2012 facebook wetube 1 4-12-2012 </code></pre> <p>and i have this query code to fetch the friends of user called wetube.</p> <pre><code>mysql_query("SELECT f.* FROM friends f inner join users u on u.username = f.you WHERE f.friend = 'wetube' UNION ALL SELECT f.* FROM friends f inner join users u on u.username = f.friend WHERE f.you = 'wetube'"); </code></pre> <p>now what I want exactly is how to fetch the friens of wetube and show it to him on his page.</p> <p>fixed:</p> <p>Finally I fixed the problem. so this is the table:</p> <pre><code>CREATE TABLE IF NOT EXISTS `friends` ( `id` int(20) NOT NULL AUTO_INCREMENT, `you` varchar(255) NOT NULL, `friend` varchar(255) NOT NULL, `type` varchar(255) NOT NULL, `since` date NOT NULL, `message` text NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; </code></pre> <p>and this is the php code to fetch the user friends</p> <pre><code>&lt;?php $username = $_SESSION['username']; $friends_sql = mysql_query("SELECT * FROM friends WHERE (friend = '$username' OR you = '$username') "); while($friends_row = mysql_fetch_assoc($friends_sql)){ if ($username == $friends_row['you']) { echo $friends_row['friend']."&lt;br/&gt;"; } elseif($username == $friends_row['friend']) { echo $friends_row['you']."&lt;br/&gt;"; } } ?&gt; </code></pre> <p>try it yourself it works 100%</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload