How to list mysql results grouped by one column value, groups listed bellow - 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: How to list mysql results grouped by one column value, groups listed bellow (/showthread.php?tid=91452) |
How to list mysql results grouped by one column value, groups listed bellow - Miha71 - 08-12-2024 I have table "properties" with columns id, name, location, type, price, sq_ft and some other... I want properties to be listed grouped by value of "type"column (i.e. values in this columns are Townhome, Appartment, Condo). But, with "type" values as titles of the groups, and dinamically so when I add new value in type column i.e. "Commercial" those properties are listed too. So, what I want is: Townhome Townhome Property 1 Townhome Property 2 Appartment Appartment Property 1 Appartment Property 2 Condo Condo Property 1 Condo Property 2.... and bellow this, after adding "Commercial" in type column Commercial Commercial Property 1 Commercial Property 2 So, basically, any new type of properties is dinamically added with its properties and with title of type. I am doing this in CodeIgniter 4 and so far I managed to list properties only per one type per page/view. Cotroller: Code: public function getByPropType($type) View: PHP Code: <?php foreach($properties as $prop) : ?> RE: How to list mysql results grouped by one column value, groups listed bellow - luckmoshy - 08-13-2024 https://codeigniter.com/user_guide/database/query_builder.html#query-grouping RE: How to list mysql results grouped by one column value, groups listed bellow - christianberkman - 08-16-2024 Using your code as an example, I would to the following: PHP Code: // controller However, a better practice would be to
PHP Code: // controller |