I got a simple if else statement where I show a list of pdf files, when the id is empty (aka there is no pdf file) I want to show: 'No available downloads'. But it shows that text no matter what, even if there are pdf files present.
My code:
<div class="widget broucher">
<h4>DOWNLOADS</h4>
<ul>
<?
//pdf bestanden
$pdf = "SELECT * FROM `snm_attachments` WHERE parent_id = '".$conn->real_escape_string($contentcr[0]['id'])."'";
$pdfcon = $conn->query($pdf);
$pdfcr = array();
while ($pdfcr[] = $pdfcon->fetch_array());
foreach($pdfcr as $pdf){
if($pdf['id'] != ''){
$downloads .= '<li><a href="cms/attachments/article/'.$contentcr[0]['id'].'/'.$pdf['filename'].' "target="_blank"><i class="fa fa-file-pdf-o"></i>'.$pdf['filename'].'</a></li>';
}else{
$downloads .= '<li>No available downloads</li>';
}
}
echo $downloads;
?>
</ul>
</div>
Why is it always showing, even when there is no id
present for a row?