i.one i.one - 1 year ago 66
Ajax Question

how to use if in row datatable

i have problem with if in row datatables,
I want to output the statement APPROVED if table row column status is 1. And table row column status is 2 the statement WAITING. Now i want to output the statement only.so here my code:

$row->end_date = $row->end_date;
$row->status = '<span class=" '.if($row->status==2) {echo 'label label-sm label-success';} else if($row->status==1) {echo 'label label-sm label-warning';} else { echo 'label label-sm label-info';}?> ">
<?php if($row->status==2) {echo 'Approved';}else if($row->status==1) { echo 'Waiting';} else { echo 'Processing';}?></span>';

code in above has error.

how to use if in row datatables?

Answer Source

You have syntax error. First set the class into a variable, and then concat it to your string:

$class = 'label label-sm label-info'; //sets the default value
if ($row->status == 2) {
    $class= 'label label-sm label-success';
} else if ($row->status == 1) {
    $class = 'label label-sm label-warning';
$row->status = '<span class="'. $class . '">';

I suggest you to use an IDE like Netbeans, PHPStorm, etc... Those tools are shows you your syntax errors when you are coding.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download