I'm using an if statement in PHP whereby if a query is empty it doesn't run the PHP effectivily hiding that part of the web page. This is the if statement I'm using
if(!empty($result4)){
}
It works fine elsewhere when used to hide individual empty rows from a whole result but when run for a whole query it doesn't work.
This is the whole php code everything below if(!empty($result4)){ should not happen if query is empty, but it is.
<?php
if(!empty($result4)){
printf('<h2>%s News' . PHP_EOL, $row['name']);
$sLastStory = '';
foreach ($result4 AS $row4)
{
$sStory = $row4['headline'] . $row4['story'];
if (strcasecmp($sStory, $sLastStory) != 0)
{
if (!empty($sLastStory))
{
}
$sLastStory = $sStory;
printf('<h3>%s</h3>' . PHP_EOL, $row4['headline']);
printf('<h4>%s</h4>' . PHP_EOL, $row4['Displaydate']);
printf('<p>%s</p>' . PHP_EOL, $row4['story']);
}
if(!empty($row4['url'])){
printf('
<a href="/images/%s%s.jpg" rel="lightbox[%s]" title="%s - Credit - %s" >
<img src="/images/%s%s-thumb.jpg" style="max-height: 230px; max-width: 230px" alt="%s"/></a>' . PHP_EOL, $row4
['url'], $row4['alt'], $row4['headline'], $row4['description'],$row4['credit'], $row4['url'], $row4['alt'],
$row4['alt'] );
}
}
printf('
<br>
<hr>
<a class="bloglink" href="parknews.php?park_id=%s">See all %s news</a></li>' . PHP_EOL, $park_id, $row
['name']);
}
?>
Any ideas how to make it work?
If it helps this is the MySQL query:
$park_id = $_GET['park_id'];
$query4= 'SELECT headline, story, DATE_FORMAT(date, "%d-%M-%Y") AS Displaydate, url, alt, description, credit
FROM tpf_news
LEFT JOIN tpf_images ON tpf_news.news_id = tpf_images.news_id
Where tpf_news.park_id = ' . $park_id .' ORDER BY date DESC';
$result4 = $pdo->query($query4);
Thanks