I have a little panel on the site’s home page which should show news items recently submitted. If there are no news items, the panel is not shown. There is a form which sends an item to a DB table. This works, I have checked the DB, so no problem there.
Back on the home page, the panel is only showing one news item (there are two) and I am sure the problem lies with my while loop:
<?php
include('navbar.html');
include('joinin.inc.php');
$conn = dbconnect('query');
$sql = 'select * from news order by newsdate limit 3';
$res = $conn->query($sql);
$row = mysqli_fetch_assoc($res);
$thehead = $row['heading'];
$thetext = $row['newsitem'];
$numrows = $res->num_rows;
$style = "";
if ($numrows==0){$style = " style='display:none;'";}
//ensures if the count is zero the panel is not shown
?>
//simple html here, no PHP
//the panel
<div style="position:absolute ; left:80% ; top:100px ; width:18% ; height:auto ; color:white" <?php echo $style;?>>
<h2 style="color:red">Latest News</h2>
<?php
while($row = $res->fetch_assoc())
{?>
<h3 style="color:darkseagreen;"><?php echo ucwords($thehead);?></h3>
<span style="font-size:90%;line-height:1.4;padding:0 20px 10px 0 ; margin-top:-12px; display:inline-block">
<?php echo $thetext;}?></span><br/>
</div>
//end of panel
I have run this through a PHP checker and it finds no errors.