I need not want to display the rows which are having null values, for example if "$Banner" is having no value(i mean Null) then i will skip displaying filmBanner and echo next row called "Distributor"
Here is my code:
$sql = "SELECT * FROM films ASC LIMIT 0 , 30";
$result = mysql_query($sql);
?>
while($row = mysql_fetch_array($result))
{
$Banner=$row['Banner'];
$Distributor=$row['Distributor'];
$Screenplay=$row['Screenplay'];
<table>
<tr>
<td><b>Banner / Studio:</b></td>
<td><?php echo"$Banner";?></td>
</tr>
<tr>
<td><b>Distributed by:</b></td>
<td><?php echo"$Distributor";?></td>
</tr>
<tr>
<td><b>Screenplay</td>
<td><?php echo"$Screenplay";?></td>
</tr>
</table>
output needed as: if banner = null then skip banner and display next column. so here i want to write loop in "table" itself not in sql query.
This was the code i used before and was running perfectly but showing even Null Values
<?php
$sql = "SELECT * FROM films";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$filmBanner=$row['filmBanner'];
$filmDistributor=$row['filmDistributor'];
$filmScreenplay=$row['filmScreenplay'];
?>
<table>
<tr>
<td><b>Banner / Studio:</b></td>
<td><?php echo"$filmBanner";?></td>
</tr>
<tr>
<td><b>Distributed by:</b></td>
<td><?php echo"$filmDistributor";?></td>
</tr>
<tr>
<td><b>Screenplay</td>
<td><?php echo"$filmScreenplay";?></td>
</tr>
</table>
<?php
}
mysql_free_result($result);
mysql_close();
?>
and Now i have replaced entire as following:
<?php
$sql = "SELECT * FROM films";
$result = mysql_query($sql);
?>
<?php
$columns = [["filmBanner","Banner / Studio:"],["filmDistributor","Distributed by:"],["filmScreenplay","Screenplay"]];
foreach($columns as $column){
$$column[0] = $row[$column[0]];
If($$column[0]!=null){
?>
<tr>
<td><b><?php echo $column[1]; ?></b></td>
<td><?php echo $$column[0];?></td>
</tr>
<?php
}
}
mysql_free_result($result);
mysql_close();
?>