![]() |
|
[PHP] PHP Echo Mysql Data from 2 tables BY newest data - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183) +---- Thread: [PHP] PHP Echo Mysql Data from 2 tables BY newest data (/showthread.php?tid=5238767) |
PHP Echo Mysql Data from 2 tables BY newest data - CodeBinary - Apr 15, 2016 I asked stackoverflow but so far no one responded :( So I am trying to echo the 10 newest data from 2 different tables. Ive tried Code $stmt60 = $db->prepare("SELECT * FROM 54x2 ORDER BY date_time DESC LIMIT 5");did that about 10 times with offsets increasing by 1 then added them to arrays then did like a 100 if statements checking whcih one is newer but ive tried for hours doing that and I couldn't get it to work. Is there an easier way of doing this without making 100-200 if statements? * - gua - Apr 15, 2016 I think you need for each loop there Sent from mobile * - Hash G. - Apr 15, 2016 Please change your variable names. You can't just keep them like that. And yes, you need to do a for/while/foreach loop. * - newQuery - Apr 15, 2016 OP try this: PHP Code * - CodeBinary - Apr 15, 2016 (Apr 15, 2016 04:09 PM)▷▶ ᶠᶸᶜᵏ ᵧₒᵤ ◀◁ Wrote: OP try this: Wont that always put dd table on the bottom though * - newQuery - Apr 15, 2016 (Apr 15, 2016 04:42 PM)Dashy Wrote: Wont that always put dd table on the bottom though Yes, all the datas from 54x2 would be at the top and all the datas from dd would be under the 54x2's datas * - CodeBinary - Apr 15, 2016 (Apr 15, 2016 04:46 PM)▷▶ ᶠᶸᶜᵏ ᵧₒᵤ ◀◁ Wrote: Yes, all the datas from 54x2 would be at the top and all the datas from dd would be under the 54x2's datas Oh im trying to put which ever one is newer on the top :/ * - newQuery - Apr 15, 2016 PHP Code Did this from mobile, let me know if it's working * - CodeBinary - Apr 16, 2016 (Apr 15, 2016 05:26 PM)▷▶ ᶠᶸᶜᵏ ᵧₒᵤ ◀◁ Wrote: Got an error: Code Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, dd AS 2 ORDER BY date_time DESC LIMIT 5' at line 1 in C:\wamp\www\runewin\home.php on line 200 |