Jump to content
php.lv forumi

Recommended Posts

Posted

Sveiki, mēģinu panāk, ka no divām tabulām datus saliek kopā un izvad augošā secībā pec laika
 

$comments = ORM::for_table('comments')->where('uid', $id)->find_array();
$replays = ORM::for_table('comment_replays')->where('uid', $id)->find_array();
$opinions = array_merge($comments, $replays);

foreach($opinions as $item => $key){
        echo $item.' = '.$key['time'].'<br>';
}
Posted

Sakārto pēc abu tabulu komentu timestampiem, tos ņemot kā masīva key. Diez vai būs kāds komentāra timestamp, kas eksistēs abās tabulās.

Array_merge vietā izmanto  $comments + $replays

Posted (edited)

$opinions = array_merge($comments, $replays);

usort($opinions, function ($a, $b)

{

return $a['time'] <=> $b['time']; // PHP 7 spaceship operator

});

Edited by jurchiks
Posted

Labi, principā es vispār nesaprotu, nafig viņš merdžo un kārto komentārus un replies pēc datumiem, nevis pēc parent id un tikai tad pēc datumiem.

Bet tas ir pie kājas; jautājums bija "kā no divām tabulām datus saliek kopā un izvad augošā secībā pec laika", un uz to ir atbildēts.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...