ziedinjsh Posted November 24, 2016 Report Share Posted November 24, 2016 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>'; } Quote Link to comment Share on other sites More sharing options...
Val Posted November 24, 2016 Report Share Posted November 24, 2016 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 Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 24, 2016 Author Report Share Posted November 24, 2016 Laikam nesapratu, kā tas varētu izskatīties Quote Link to comment Share on other sites More sharing options...
jurchiks Posted November 24, 2016 Report Share Posted November 24, 2016 (edited) $opinions = array_merge($comments, $replays); usort($opinions, function ($a, $b) { return $a['time'] <=> $b['time']; // PHP 7 spaceship operator }); Edited November 24, 2016 by jurchiks Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 24, 2016 Author Report Share Posted November 24, 2016 Paldies! Quote Link to comment Share on other sites More sharing options...
Sasa Posted November 30, 2016 Report Share Posted November 30, 2016 ORM'am pasaki ka vajag arī sakārtot. Īsumā no DB atgriez jau sakārtotus datus. Quote Link to comment Share on other sites More sharing options...
jurchiks Posted November 30, 2016 Report Share Posted November 30, 2016 Viņam ir 2 atsevišķi pieprasījumi... Quote Link to comment Share on other sites More sharing options...
jurchiks Posted December 1, 2016 Report Share Posted December 1, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.