gtviga gtviga - 4 months ago 12
SQL Question

Data from MySQL changing from no data into zero

I have this table of "score" in my database

! id ! A !
-----------------
! 01 ! 10 !
! 02 ! !
! 03 ! !
! 04 ! 5 !




$mySql = "SELECT score.id, score.A
FROM score
ORDER BY score.id ASC";
$myQry = mysql_query($mySql, $koneksidb) or die ("Query salah : ".mysql_error());
while ($myData = mysql_fetch_array($myQry)) {
$id=$myData['id'];
$A=$myData['A'];
}


When I call with

<?php echo $A; ?>




It came out with zero instead of no data,

! id ! A !
-----------------
! 01 ! 10 !
! 02 ! 0 !
! 03 ! 0 !
! 04 ! 5 !




What should I change?

Answer

Well if they are null values they will be echoed as 0.

You can do this ternary hack:

<?php echo ($A==0)?' ':$A; ?>

I didn't test, but I believe it will work. Maybe you could do that, also:

<?php echo (isset($A))?$A:' '; ?>

Also, quit using mysql_* functions, please!

Comments