How to hide mysqli null row

97 Views Asked by At

I have the following code and i need to hide area2 and adsec2 if in my mysql table are empty.

here is my code

      while($row = mysqli_fetch_array($resultFilmCerts)) {
            echo "\t<tr><td>".$row['pn']."</td><td>".$row['fname']."</td><td>".$row['lname']."</td><td>".$row['careerin']."</td><td>".$row['careerout']."</td><td>".$row['area1']."-".$row['adsec1']."<br>".$row['area2']."-".$row['adsec2']."</td><td>View <i>thematic </i>career</td></tr>\n";
        }
3

There are 3 best solutions below

0
On

check for null.

while($row = mysqli_fetch_array($resultFilmCerts)) {

$area1 = ($row["area1"] == null ? "" : $row["area1"]);
$adsec1 = ($row["adsec1"] == null ? "" : $row["adsec1"]);

add these two lines above your echo statement.

echo "\t<tr><td>".$row['pn']."</td><td>".$row['fname']."</td><td>".$row['lname']."</td><td>".$row['careerin']."</td><td>".$row['careerout']."</td><td>".$area1."-".$adsec1."<br>".$row['area2']."-".$row['adsec2']."</td><td>View <i>thematic </i>career</td></tr>\n";
0
On

I think you need to apply relation between your tables. Then use LEFT JOIN. In received data from query, hide td (with colspan if necessary) if value is null or unavailable.

0
On

i hope it will help you..With the of this you can count the numbers of rows from database.

$rowcount=mysqli_num_rows($result); if($rowcount>0){ //diplasy your data}else{  }