----------------- sql -------------------------
CREATE TABLE IF NOT EXISTS `friend` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(30) DEFAULT NULL,
`friends` text,
PRIMARY KEY (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
--
-- Dumping data for table `friend`
--
INSERT INTO `friend` (`uid`, `username`, `friends`) VALUES
(1, 'admin1', 'a:2:{i:0;s:1:"4";i:1;s:1:"5";}'),
(2, 'admin2', ''),
(3, 'admin3', ''),
(4, 'admin4', 'a:1:{i:0;s:1:"1";}'),
(5, 'admin5', 'a:1:{i:0;s:1:"1";}'),
(6, 'admin6', '');
CREATE TABLE IF NOT EXISTS `tweets` (
`t_id` int(11) NOT NULL AUTO_INCREMENT,
`tweet` varchar(140) COLLATE utf8_unicode_ci NOT NULL,
`uid` int(11) NOT NULL,
`time` int(11) NOT NULL,
PRIMARY KEY (`t_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19 ;
--
-- Dumping data for table `tweets`
--
INSERT INTO `tweets` (`t_id`, `tweet`, `uid`, `time`) VALUES
(12, 'ada ad ad', 1, 1351424529),
(13, 'a dadeee', 4, 1351424532),
(14, 'sasa', 2, 1351424620),
(15, 'asdaa', 1, 1351425426),
(16, 'asdasd asd', 3, 1351426554),
(17, 'asd as das', 5, 1351426556),
(18, 'as das d', 1, 1351426557);
--------------- index.php -------------
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("bacan");
function time_stamp($session_time)
{
$time_difference = time() - $session_time ;
$seconds = $time_difference ;
$minutes = round($time_difference / 60 );
$hours = round($time_difference / 3600 );
$days = round($time_difference / 86400 );
$weeks = round($time_difference / 604800 );
$months = round($time_difference / 2419200 );
$years = round($time_difference / 29030400 );
if($seconds <= 60)
{
echo"$seconds s";
}
else if($minutes <=60)
{
echo"$minutes m";
}
else if($hours <=24)
{
echo"$hours hours ago";
}
else if($days <=7)
{
echo"$days d";
}
else if($weeks <=4)
{
echo"$weeks w";
}
else if($months <=12)
{
if($months==1)
{
echo"one month ago";
}
else
{
echo"$months months ago";
}
}
else
{
if($years==1)
{
echo"one year ago";
}
else
{
echo"$years years ago";
}
}
}
$uid= 1;
$query = mysql_query("SELECT friends FROM friend WHERE uid = '" . $uid. "'");
while($row = mysql_fetch_array($query)) {
$friends = unserialize($row["friends"]);
if(isset($friends[0])) {
foreach($friends as $friend) {
$_query = mysql_query("SELECT uid FROM friend WHERE uid = '" . $friend . "'");
while($_row = mysql_fetch_array($_query)){
$sql="select * from tweets T, friend F where f.uid = ".$_row['uid']." and F.uid=T.uid order by time DESC";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$time = $row["time"];
echo $row["username"] . "<br>";
echo $row["tweet"];
echo "-------";
echo time_stamp($time);
echo "<br><br>";
}
}
}
}
?>