----------------- 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>";
}
      }
    }
  }

?>
Member Avatar for diafol

You could do this in SQL:

... ORDER BY `time`

... ORDER BY `time` DESC

where?
$sql="select * from tweets T, friend F where f.uid = ".$_row['uid']." and F.uid=T.uid order by time DESC";

Member Avatar for diafol

Yes. As you've done. Does it not work for you?

Probably forgot the backticks...

does not work. you try to save the code and try

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);

look comment down

Member Avatar for diafol

OUTPUT

a dadeee-------1 d

asd as das-------1 d

What are you expecting?

@diafol nononooooo it appears only 1 message. I want to highlight all the messages depends on friends. try your download link above

Member Avatar for diafol

With respect I cresated your tables and ran your code, I'm not going to download a bunch of files. Sorry. If you can give a mockup of the expected results and format, that would help.

it is only 3kb :(

We are not a coding service. We will help you find the problem if you show some effort in trying to solve it. "it doesn't work" is a useless comment. Try to find out what line is giving you a problem. Note that running a query may fail, or return no results. You need to check for that.

Member Avatar for diafol

it is only 3kb :(

That's really not the point. You are not a trusted source. If you can't express what you need in a forum, how do you think I'm going to cope with a bunch of code? Not happening.

And Pritaeas is right. Be more specific with regard to the problem.

so, what should I do? I no longer knew to whom to ask?

hmm let me get this straight. if you make

$ _query = mysql_query ("SELECT * FROM friend F, tweets WHERE T.uid T = F.uid and T.uid = '". $ friend. "' ORDER BY time DESC");

INSERT INTO tweets (t_id, tweet, uid, time) VALUES
(12, 'no 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);

$ friend not only 1 ID
and $ friend = (id your friends) like 4, 5
how to tweet your way to display the sort with time?
Do you have any ideas?
because ORDER BY time DESC only affect the 1 ID.
like this:

4 ------- 3 days ago
4 ------- 6 days ago
5 ------- 3 days ago
5 ------- 5 days ago

or, if this code matter?

   $ query = mysql_query ("SELECT friend FROM friends WHERE uid = '". $ uid. "'");
   $ row = mysql_fetch_array ($ query);
     $ friends = unserialize ($ row ['friends']);
       foreach ($ friends as $ friend) {

==================for the last time. tried your save and try this code==================

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";
  }
}
} 
?>

<?php
$uid= 1;
  $query = mysql_query("SELECT friends FROM friend WHERE uid = '" . $uid. "'");
  $row = mysql_fetch_array($query);
    $friends = unserialize($row["friends"]);

      foreach($friends as $friend) {

$_query = mysql_query("SELECT * FROM friend F, tweets T WHERE T.uid=F.uid and T.uid='" . $friend . "' ORDER BY time DESC");
while($_row = mysql_fetch_array($_query)){

$time = $_row["time"];
echo $_row["tweet"];
echo "-------";
echo time_stamp($time);
echo "<br><br>";

}
  }

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.