php - If statement is working whereas Else statement does not work -


<?php   // check connection       $servername = "localhost";      $username = "root";      $password = "1234";      $dbname = "project";       htmlspecialchars($a = $row1['stno']);       $d1 = $row7['userid'];         // create connection                $conn = new mysqli($servername, $username, $password, $dbname);        // check connection                 if ($conn->connect_error) {                      die("connection failed: " . $conn->connect_error);                 }                   $sql = "select * likes rec = $a";                 $result = $conn->query($sql);                  if ($result->num_rows > 0) {                     // output data of each row                     while($row = $result->fetch_assoc()) {                          $z4 = $row['do'];                          if ($d1 == $z4)                          {                              include ("unlikee.php");                          }                          else {                              include ("likee.php");                          }                     }                 }                  $conn->close();        ?> 

this button connected sql working fine , problem else statement

            else          include ("likee.php"); 

it's not working whereas if statement works out. logic unlikee.php contains script unlike likee.php contains vice versa , , whenever placed , unlike button shown whenever no , button invisible

you said "whenever there no like, button invisible". that's because never execute part of code includes or unlike buttons when there no likes

if ($result->num_rows > 0) { 

updated code segment. when number of result rows 0 else executed include likee.php

if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) {      $z4 = $row['do'];     if ($d1 == $z4) {           include ("unlikee.php");     }  } else {     include ("likee.php"); } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -