duan201444 2017-04-08 02:23
浏览 21
已采纳

如何在PHP中不显示空值

:) Can you help me not show null values? Here's my code: eeeeeeee

require 'databasename.php';
if (isset($_GET['id'])) { 
require 'databasename.php';
$id = mysqli_real_escape_string($connect, $_GET['id']);

$sql = "SELECT * FROM `example` WHERE id = '$id'";
$result = $connect->query($sql);

while($data = $result->fetch_assoc()) {

echo "<div id='moveresults'>";

echo "<div id='as'>";
echo $data['As'];
echo "</div>";

echo "<div id='so'>";
    echo $data['SO'];
echo "</div>";


echo "<div id='custom'>";
    if($data['Custom'] != '' || $data['Custom'] != NULL) {
    echo $data['Custom'];   
    }
echo "</div>";

echo "<div id='local'>";
    if($data['Address'] != '' || $data['Address'] != NULL) {
    echo $data['Address'];  
    }
echo "</div>";

echo "<div id='headof'>";
    if($data['Head'] != '' || $data['Head'] != NULL) {
    echo $data['Head']; 
    }
echo "</div>";

echo "<div id='credl'>";
    if($data['Credit'] != '' || $data['Credit'] != NULL) {
    echo $data['Credit'];   
    }
echo "</div>";

echo "<div id='currenta'>";
    echo $data['Current'];
echo "</div>";

echo "<div id='totalex'>";
    echo $data['Exposure'];
echo "</div>";

echo "<div id='termspay'>";
    if($data['Payment'] != '' || $data['Payment'] != NULL) {
    echo $data['Payment'];  
    }
echo "</div>";

echo "<div id='overdue'>";
    echo $data['Overdue'];
echo "</div>";

echo "<div id='pdc'>";
    echo $data['PDC'];
echo "</div>";

echo "<div id='pending'>";
    echo $data['Pending'];
echo "</div>";

echo "<div id='overallex'>";
    echo $data['Overall'];
echo "</div>";

echo "</div>";

}

?>

I tried the if ! which I saw in another post but I'm thinking it's either I typed wrong format or there's another way around. Thanks again.

  • 写回答

4条回答 默认 最新

  • duan111112 2017-04-08 02:32
    关注

    try to populate your whole div in the if statement like this:

    if($data['Custom'] != '' || $data['Custom'] != NULL) {
      echo "<div id='overdue'>";
         echo $data['Custom'];
      echo "</div>";   
    }
    

    And of course you need to apply this to all your divs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中
  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信