Hello! I want to display photos that are in the database and which are not, that is, if there is a photo in the database, then it displays images that are, if not, then it displays just the default photo. The problem in the cycle finds at least one photo of which is not and puts everywhere by default, that's how I'm trying to do
if($result->rowCount() > 0){ while ($myrow = $result->fetch(PDO::FETCH_ASSOC)){ $id = $myrow["id"]; $job_vacancy = $myrow["job_vacancy"]; $my_content = $myrow["my_content"]; $catalog = $myrow["catalog_small"]; $filename = $myrow["filename_small"]; $file = explode(",", $filename); $short_link = substr($my_content, 0, 94); foreach ($file as $key) { echo " <div class='col-sx-12 col-md-4'> <div class='card'>"; if(file_exists($catalog.$key)){ echo "<img class='card-img-top' src='".$catalog."/".$key."' alt='Card image cap'>"; } else{ echo "<img src='https://2oq.ru/my_room/img/avatar.png' class='img-thumbnail'> "; } echo " <div class='card-block'> <h4 class='card-title'>".$job_vacancy."</h4> <p class='card-text'>".$short_link."</p> <a href='https://2oq.ru/info/?id=".$id."' class='btn btn-primary'>Подронее</a> </div> </div> </div> "; } } } or so
if($result->rowCount() > 0){ while ($myrow = $result->fetch(PDO::FETCH_ASSOC)){ $id = $myrow["id"]; $job_vacancy = $myrow["job_vacancy"]; $my_content = $myrow["my_content"]; $catalog = $myrow["catalog_small"]; $filename = $myrow["filename_small"]; $file = explode(",", $filename); $short_link = substr($my_content, 0, 94); foreach ($file as $key) { echo " <div class='col-sx-12 col-md-4'> <div class='card'> <img class='card-img-top' src='".$catalog."/".$key."' onerror = 'this.style.display = 'none'' alt='Card image cap'> <div class='card-block'> <h4 class='card-title'>".$job_vacancy."</h4> <p class='card-text'>".$short_link."</p> <a href='https://2oq.ru/info/?id=".$id."' class='btn btn-primary'>Подронее</a> </div> </div> </div> "; } } }