Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed following code to show database fetched items when user clicked a button. For one button following code work perfect. So I used the same code for the second button to show query result after changing the variables. But when the second button is clicked it shows this error message

Warning: mysqli::query(): Couldn't fetch mysqli
Notice: Trying to get property 'num_rows' of non-object in
0 results
Warning: mysqli::close(): Couldn't fetch mysqli in


It is true that similar problem have occurred and answers have published to them. I tried those and still I can't understand where my mistake is.
A help to catch my mistake would be really admired
Thank you

What I have tried:

<?php
                      $sql = "SELECT * FROM services  where service='Vehicle_Hiring'
                      ";
                      $result = $con->query($sql);
                      if ($result->num_rows > 0) {
                      while ($row = $result->fetch_assoc()) {
                      ?>
          <div class="col-lg-3" style="border: outset;">
              <div class="header">
                      <?php echo '<img src="' . $row['image_path4']. '" width="100" height="100">'; ?>
              </div>
              <div class="body">
                      <h4><?php echo $row ['name']; ?></h4>
                      class="fa fa-envelope-square"><?php echo $row ['email']; ?></br>
                      class="fa fa-address-book"><?php echo $row ['address']; ?></br>
                      <?php echo $row ['years']; ?></br>
                      class="fa fa-info"><?php echo $row ['details']; ?>
              </div>
              <div style="background-color: #000000">
                      <font color="#FFFFFF"><?php echo $row ['district']; ?></font>
                      <font color="#FFFFFF"><?php echo $row ['city']; ?></font>
              </div>

          </div>

                      <?php
                         }
                      } else {
                         echo "0 results";
                      }
                      $con->close();
                      ?>
Posted
Updated 24-Sep-20 20:55pm

The problem was in
$con->close();
I was closing the connection too early. when I removed that problem was solved
 
Share this answer
 
it also works for me folks. thanks. there are too many days i am stuck in there.
we close the connection too early.

$db->close();
 
Share this answer
 
Warning: mysqli_query(): Couldn't fetch mysqli in /home/u193961646/domains/myjss.online/public_html/test.php on line 12

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u193961646/domains/myjss.online/public_html/test.php on line 13

Notice: Undefined variable: ti in /home/u193961646/domains/myjss.online/public_html/test.php on line 17
Warning: mysqli_query(): Couldn't fetch mysqli in /home/u193961646/domains/myjss.online/public_html/test.php on line 20

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u193961646/domains/myjss.online/public_html/test.php on line 21

Notice: Undefined variable: jssblock in /home/u193961646/domains/myjss.online/public_html/test.php on line 25




include'newc.php';
// error_reporting(0);
error_reporting(E_ALL);
ini_set('display_errors', '1');




$runt=mysqli_query($conn,"SELECT * FROM `Recharge_offer` WHERE id=2");
while($rowt=mysqli_fetch_array($runt)){ $ti=$rowt['offer5'];
;}


echo"off=".$ti;


$run=mysqli_query($conn,"SELECT * FROM `onoff` WHERE id=7"); //ORDER BY id DESC LIMIT 0,50
while($row=mysqli_fetch_array($run)){
$jssblock=$row['paidjoinung']; $offerblock=$row['freejoining'];
}

echo"
on".$jssblock;


?>
 
Share this answer
 
Comments
Richard Deeming 25-Sep-20 4:40am    
Your question is not a solution to someone else's question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900