mysql - PHP if query not behaving correctly -
i'm using if statement in php whereby if query empty doesn't run php effectivily hiding part of web page. if statement i'm using
if(!empty($result4)){ }
it works fine elsewhere when used hide individual empty rows whole result when run whole query doesn't work.
this whole php code below if(!empty($result4)){ should not happen if query empty, is.
<?php if(!empty($result4)){ printf('<h2>%s news' . php_eol, $row['name']); $slaststory = ''; foreach ($result4 $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 %s news</a></li>' . php_eol, $park_id, $row ['name']); } ?>
any ideas how make work?
if helps mysql query:
$park_id = $_get['park_id']; $query4= 'select headline, story, date_format(date, "%d-%m-%y") displaydate, url, alt, description, credit tpf_news left join tpf_images on tpf_news.news_id = tpf_images.news_id tpf_news.park_id = ' . $park_id .' order date desc'; $result4 = $pdo->query($query4);
thanks
if query succeeded, pdo::query()
return pdostatement
if no rows selected. since $result4
contains pdostatement
, not empty.
a better way check number of returned rows pdostatement::rowcount:
if( $result4->rowcount() ){
Comments
Post a Comment