I have this following piece of code
include_once("config/connection.php");
$sql = "SELECT * FROM qqqq WHERE LOWER(pdf_ad) LIKE '%" . $aranacak_metin . "%'";
$result = $DBcon->query($sql);
if ($result && is_array($result) && count($result) > 0) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$yeniad = seo($row['pdf_ad']);
echo '<form action="/indir/' . $yeniad . '/' . $row['pdf_liste_no'] . '" id="sorgu" method="post">';
echo '<li class="list-group-item">';
echo '<input type="hidden" name="id" value="' . $row['pdf_liste_no'] . '">';
echo '<input type="hidden" name="name" value="' . $row['pdf_ad'] . '">';
echo '<img alt="' . $row['pdf_ad'] . '" src="' . $row['pdf_resim'] . '" width=120" height="150"><a style="font-size:20px; text-decoration:none; color:black;" href="#"> ' . $row['pdf_ad'] . '</a> ';
echo '<button type="submit" class="btn btn-success">';
echo '<i class="fa fa-arrow-circle-right fa-lg"></i>';
echo '</button>';
echo '</li>';
echo '</form>';
}
} else {
echo $aranacak_metin;
}
if statement does its job if the result is set shows the rows but if there is no match in DB else statement
doesnt work am i missing something need your help thank you
update:it turns else everytime now
3
Answers
Changed my php version it worked ?
in current scenario
$result
is always set. so just check you got any match record or not, based on that put conditions as below.if its PDO query then
Try below code: