-2

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?

AkshayP
  • 2,141
  • 2
  • 18
  • 27
gtviga
  • 91
  • 5

3 Answers3

0

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!

Community
  • 1
  • 1
Phiter
  • 14,570
  • 14
  • 50
  • 84
  • 1
    @gtviga if it works you should mark this answer as accepted. Green tick near the voting buttons – Matt Jul 07 '16 at 12:46
0

That's all right. Simplify,

$any_empty_var == false == 0

So, you can just add the condition

if ($A == 0) echo " ";
else echo $A; 
Maksim I. Kuzmin
  • 1,170
  • 7
  • 16
0

!.) You should use mysqli as mysql is obsolete. 2.) set score.A so that it can simple diplay null values

ALTER TABLE score CHANGE A INT(11) NULL; the mysql will return a null value

Martin S.
  • 256
  • 1
  • 10