如果SQL值为空,则输出文本

时间:2017-04-29 12:19:04

标签: php sql html-table

如果在我的SQL表中存储了一个空值,我正在尝试将文本'N / A'输出到我的表中。以下是我到目前为止的情况:

while($rowObj = $queryResult->fetch_object())
                {
                $eventTitle = $rowObj->eventTitle;
                $catDesc = $rowObj->catDesc;
                $catID = $rowObj->catID;
                $eventDescription = $rowObj->eventDescription;
                $venueName = $rowObj->venueName;
                $venueID = $rowObj->venueID;
                $eventStartDate = $rowObj->eventStartDate;
                $eventEndDate = $rowObj->eventEndDate;
                $eventPrice = $rowObj->eventPrice;                  

                echo "
                <tr>
                    <td> $eventTitle </td>
                    <td> " . (empty($catID)) ? 'N/A' : '$catDesc'. "</td>
                    <td> " . (empty($eventDescription)) ? 'N/A' : '$eventDescription'. "</td>
                    <td> " . (empty($venueID)) ? 'N/A' : '$venueName'. "</td>
                    <td> $eventStartDate </td> 
                    <td> $eventEndDate </td>
                    <td> $eventPrice </td>
                </tr>
                    ";
                }

2 个答案:

答案 0 :(得分:0)

if(empty($value)){
    echo "This value is empty";
}

或者 如果你想在表中插入一个值&#34;&#34;如果字段为空

if(empty($value)){
 $value = "N/A";
 //INSERT QUERY
}

答案 1 :(得分:0)

试试这个

$ value =空($ value)? “NA”:$ value;