doutang8098 2016-01-15 21:19
浏览 151
已采纳

如果mysql任何字段为空,则显示一个像null的单词

I need to know that, if there is any empty field then display null in retrieve form. i mean,


name----------age----------country


xyz----------" "---------usa


so, the form will show

name: xyz

age: show null

country: usa

<?php
$dbhost = '';
$dbuser = '';
$dbpass = '';


$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if(! $conn ) {
  die('Could not connect: ' . mysql_error());
}
$No=$_GET['No'];
$sql = "SELECT * from tablename where Name='$Name'";
mysql_select_db('dbname');
$retval = mysql_query( $sql, $conn );

if(! $retval ) {
  die('Could not get data: ' . mysql_error());
 }

while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {

   ?>


 <table width="100%"><tr><td>
 <table>
 <tr>
 <tr><td class="a" style="width:20%">Name</td><td style="width:20%"  class="a"><a class="res" ><?php echo $row['Name'];?></a></td></tr>
 <tr><td class="a" style="width:20%">age</td><td style="width:20%"   class="a"><a class="res"><?php echo $row['age'];?></a></td></tr>
 <tr><td class="a" style="width:20%">country</td><td style="width:20%"  class="a"><a class="res"><?php echo $row['country'];?></a></td></tr>
 </tr>
 </table>

 <?php
 }


    mysql_close($conn);
 ?>`
  • 写回答

2条回答 默认 最新

  • drgovyk64676 2016-01-15 21:27
    关注

    Just test if the result is empty and if it is show Null.

    <?php if ($row['Name'] != '') {
        echo $row['Name'];
    } else {
        echo "Null";
    }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器