How to list mysql results grouped by one column value, groups listed bellow |
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) : ?>
https://codeigniter.com/user_guide/datab...y-grouping
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals
Using your code as an example, I would to the following:
PHP Code: // controller However, a better practice would be to
PHP Code: // controller |
Welcome Guest, Not a member yet? Register Sign In |