Need Idea foreach - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Need Idea foreach (/showthread.php?tid=70548) |
Need Idea foreach - googlemy - 04-25-2018 Hi CI Team, How to foreach data like below, Database : Code: ID | viewed | code How to get output like below, Code: var gdpData = {"US": 25, Thanks RE: Need Idea foreach - neuron - 04-25-2018 where your getting data from? if this data in database you can use group by and sum sql functions to get viewed | code 25 | US 85 | SG 55 | MY or if discribe it in php array: PHP Code: array( your gdpData is in json format. you will need to map to PHP Code: array( {"US":25,"SG":85,"MY":55} Also to parse json you can use json_decode function in PHP RE: Need Idea foreach [Solved] - googlemy - 04-26-2018 (04-25-2018, 11:05 PM)neuron Wrote: where your getting data from? I try use this code, PHP Code: $rv = array(); The result is OK, but how to sum the viewed ? Thanks you neuron... RE: Need Idea foreach - syedamirbukhari - 05-02-2018 You need to sum the result in SQL query, not in foreach. |