Verwenden Sie CASE
-Anweisung statt mehrerer Abfragen
Modell:
public function summary($st_date,$end_date){
$this->db->select("
SUM(CASE WHEN status = 'D' THEN 1 END) AS draft,
SUM(CASE WHEN status = 'N' THEN 1 END) AS unpublish,
SUM(CASE WHEN status = 'Y' THEN 1 END) AS publish"
);
$this->db->where('added_date >=', $st_date);
$this->db->where('added_date <=', $end_date);
return $this->db->get('crm_listings');
}
Ansicht:
Erstellen Sie kein HTML im Controller, da dies in MVC eine schlechte Vorgehensweise ist. Verwenden Sie foreach
loop in view file to show valuesLesen Sie mehr über CI-Ansichten
<div class="table-responsive">
<table class="table table-bordered table-striped">
<tr>
<th>Draft</th>
<th>Unpublish</th>
<th>Publish</th>
</tr>
<?php
if(isset($data) && count($data) > 0){
foreach($data as $row ){ ?>
<tr>
<td><?= $row->draft ?></td>
<td><?= $row->unpublish ?></td>
<td><?= $row->publish ?></td>
</tr>
<?php } //Foreach end here
} else { ?>
<tr>
<td colspan="5">No Data Found</td>
</tr>
<?php } ?>
</table>
Lesen Sie mehr über MySQL Case Statement