I need to change a value depending a result. In this case, if my row "status" is "Active" I want to put something like that in a table:
<td>'.$row['register_status'].'</td>
<td>'
if($row['status']=='Active')
{
echo '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
}
'</td>
What is wrong on code?
if(mysql_num_rows($result) > 0)
{
$number = 1;
while($row = mysql_fetch_assoc($result))
{
$data .= '<tr>
<td>'.$row['register_status'].'</td>
<td>'
if($row['status']=='Active')
{
echo '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
}
'</td>
</tr>';
$number++;
}
}
else
{
// records now found
$data .= '<tr><td colspan="6">Records not found!</td></tr>';
}
$data .= '</table>';
echo $data;
In logs, the error is:
PHP Parse error: syntax error, unexpected T_IF in /var/www/html/form/ajax/readRecords.php on line 32, referer: http:/localhostform/
when the line 32 is:
if($row['status']=='Active')
- UPDATE *
Finally I update the code as:
while($row = mysql_fetch_assoc($result))
{
$data .= '<tr>
<td>'.$row['register_status'].'</td>
<td>';
if($row['register_status']=='Active') {
$data .= '<span class="glyphicon glyphicon-true" aria-hidden="true" style="color:green"></span>';
}
else if($row['register_status']=='Inactive')
{
$data .= '<span class="glyphicon glyphicon-time-remove" aria-hidden="true" style="color:red"></span>';
}
else
{
$data .= '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
}
$data .= '</td>
<td>'.$row['first_name'].'</td>
</tr>';
}
}
else
{
$data .= '<tr><td colspan="6">Records not found!</td></tr>';
}
$data .= '</table>';
echo $data;
But always execute the last else and only print the result into
$data .= '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
Why do not put a different icon according to the different cases?