If statement in the controller while fetching data from database in Codeigniter:
There use IF statement in controller page while retrieving data from MySQL table using Codeigniter framework. In your Codeigniter web application, if you retrieve data from the database and display data in a table page without page refresh. If this time you need to apply if statement , so this tutorial will help you to solve this problem very quickly.
Return select value from Model page and store array value in an array variable. Using foreach loop fetch select data in table rows. When using select data by pass ID value or some value using jQuery and display data dynamically without page refresh access table ID name.
Follow the example and try on your web page.
Example:
public function select_balance(){ $data=$this->MyModel->selectBalance(); $view = ''; foreach ($data as $bln) { $view = $view ."<tr>"; $view = $view ."<td>".date('M,d-Y', strtotime($bln->date))."</td>"; $view = $view ."<td>".$bln->description."</td> <td>"; if($bln->credit_debit=="Credit"){ $view .="<span class='label label-sm label-danger'> Credit Balance </span>"; }else{ $view .="<span class='label label-sm label-success'> Debit Balance </span>"; } $view."</td>"; $view = $view ."<td>".$bln->pay_price."</td>"; $view = $view ."<td>".$bln->pay_price." /-</td>"; $view = $view ."</tr>"; } echo $view; }
Related posts