 <p>You have syntax error. First set the class into a variable, and then concat it to your string:</p> <pre><code>$class = 'label label-sm label-info'; //sets the default value $status = 'Processing'; if ($row-&gt;status == 2) { $class = 'label label-sm label-success'; $status = 'Approved'; } else if ($row-&gt;status == 1) { $class = 'label label-sm label-warning'; $status = 'Waiting'; } $row-&gt;status = '&lt;span class="' . $class . '"&gt;' . $status . '&lt;/span&gt;'; </code></pre> <p>I suggest you to use an IDE like Netbeans, PHPStorm, etc... Those tools are shows you your syntax errors when you are coding.</p>