php - how to count number of rows in related table -



php - how to count number of rows in related table -

i have 2 tables in database

articles next fields

id author post_date modification title section_id views featured content post_status

sections next fields

sec_id description slug category

i have function in model homecoming sections

function get_all() { $q = $this->db->select('sec_id,category,slug,description') ->from('sections') ->order_by('category','asc'); $ret['rows'] = $q->get()->result(); homecoming $ret; }

am display in table

<div id="categories"> <div id="toolbar"> </div> <table> <thead class="table_header"> <tr> <th><input type="checkbox" name="check_all" id="master_box" onclick="toggle(this)" /></th> <?php foreach($fields $field_name => $field_display):?> <th><?php echo $field_display ?></th> <?php endforeach; ?> </tr> </thead> <tfoot class="table_header"> <tr> <th><input type="checkbox" name="check_all" id="master_box" onclick="toggle(this)" /></th> <?php foreach($fields $field_name => $field_display):?> <th><?php echo $field_display ?></th> <?php endforeach; ?> </tr> </tfoot> <tbody> <?php foreach($categories $cat):?> <tr> <td><input id="sec_id"name="id[]" type="checkbox" value="<?php echo $cat->sec_id; ?>" /></td> <td><?php echo $cat->category; ?></td> <td><?php echo $cat->description; ?></td> <td><?php echo $cat->slug; ?></td> <td></td> </tr> <?php endforeach;?> </tbody> </table> </div>

if notice there empty tag.it meant display number of articles in category(section).

how number of articles associated each category?

select s.sec_id,s.category,s.slug,s.description,count(a.id) sections s left bring together articale on s.sec_id = a.section_id 1 grouping s.sec_id order s.category asc

php mysql codeigniter

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -