skip to Main Content

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


  1. Chosen as BEST ANSWER

    Changed my php version it worked ?


  2. 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($result && $result->num_rows && $result->num_rows > 0){
    
    } else {
    
    }
    

    if its PDO query then

    if($result && is_array($result) && count($result) > 0){
    
    } else {
    
    }
    
    Login or Signup to reply.
  3. Try below code:

    if ( is_array($result) && count($result) > 0 ) {
    
       // staff
    
    } else {
    
       echo $aranacak_metin;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search