Jump to content

How to add text to a null result in a table


shmideo

Recommended Posts

Or you can do it in the query

mysql> SELECT * FROM user;
+--------+------------+-----------+
| iduser | first_name | last_name |
+--------+------------+-----------+
|      1 | Stella     | NULL      |
|      2 | Amanda     | Brown     |
|      3 | Kevin      | Green     |
|      4 | John       | Wilson    |
|      5 | Helen      | NULL      |
|      6 | Pete       | Doone     |
+--------+------------+-----------+

mysql> SELECT iduser
    -> , first_name
    -> , IFNULL(last_name, '(No data)') as lastname
    -> FROM user;
+--------+------------+-----------+
| iduser | first_name | lastname  |
+--------+------------+-----------+
|      1 | Stella     | (No data) |
|      2 | Amanda     | Brown     |
|      3 | Kevin      | Green     |
|      4 | John       | Wilson    |
|      5 | Helen      | (No data) |
|      6 | Pete       | Doone     |
+--------+------------+-----------+

Thanks guys but still not filling in blank cells. $dstchannel seems to be the problem but don't know how to validate. 'dstchannel' echo's the non-empty rows ok as does the 'calldate' and 'clid'

echo "<tr><td width='20%'>";
echo $row['calldate'];
echo "</td><td width='30%'>";
echo $row['clid'];
echo "</td><td width='30%'>";
if (empty($dstchannel)) {
echo $row["no Data"];
} else {
echo $row['dstchannel'];
}
echo "</td><td width='20%' style='text-align:right'>";
echo $row['duration'];
echo "</td></tr>";

$row['dstchannel'] is the variable you want to check

if (empty($row['dstchannel'])) {
echo "No Data";
} else {
echo $row['dstchannel'];
}


// or could be written as the following using a Ternary Operator
echo empty($row['dstchannel']) ? 'No Data' :  $row['dstchannel'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.