本文介绍了如何解决警告:mysqli :: query():无法获取mysqli并注意:尝试在mysql中获取属性'num_rows'的非对象错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了以下代码,用于在用户点击按钮时显示数据库获取的项目。对于一个按钮代码工作完美。所以我在改变变量后使用第二个按钮的相同代码来显示查询结果。但是当点击第二个按钮时会显示此错误消息



警告:mysqli :: query():无法获取mysqli

注意:尝试获取非对象的属性'num_rows'

0结果

警告:mysqli :: close():无法获取mysqli in




确实发生了类似的问题,并向他们发布了答案。我尝试了那些但仍然无法理解我的错误在哪里。

帮助我抓住我的错误会非常敬佩

谢谢



我的尝试:



<?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-3style =border:outset;>
< div class =header>
<?php echo'< img src ='。$ row ['image_path4']。'width =100height =100>'; ?>
< / div>
< div class =body>
< h4><?php echo $ row ['name']; ?>< / H4>
<?php echo $ row ['email']; ?> 的< / BR>
<?php echo $ row ['address']; ?> 的< / BR>
<?php echo $ row ['years']; ?>< / BR>
<?php echo $ row ['details']; ?>
< / div>
< div style =background-color:#000000>
< font color =#FFFFFF><?php echo $ row ['district']; ?>< /字体>
< font color =#FFFFFF><?php echo $ row ['city']; ?>< /字体>
< / div>

< / div>

<?php
}
} else {
echo0 results;
}
$ con> close();
?>
解决方案



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>
                      <?php echo $row ['email']; ?></br>
                      <?php echo $row ['address']; ?></br>
                      <?php echo $row ['years']; ?></br>
                      <?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();
                      ?>
解决方案




这篇关于如何解决警告:mysqli :: query():无法获取mysqli并注意:尝试在mysql中获取属性'num_rows'的非对象错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:34