php - if mysql any field is empty then show a word like null -
i need know that, if there empty field display null in retrieve form. mean,
name----------age----------country
xyz----------" "---------usa
so, form 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 * tablename name='$name'"; mysql_select_db('dbname'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('could not 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); ?>`
just test if result empty , if show null.
<?php if ($row['name'] != '') { echo $row['name']; } else { echo "null"; }?>
Comments
Post a Comment