English 中文(简体)
无法获取 Mysqli...Call to a成员函数 在非目标上获取_assoc ()
原标题:Couldn t fetch mysqli...Call to a member function fetch_assoc() on a non-object
  • 时间:2012-05-22 03:36:14
  •  标签:
  • php
  • mysql

我完全糊涂了 我的整页代码都在下面

最初, 我拥有包含页眉. php、 侧边栏、 顶部MenuBar、 amp; 主 ContentShell 在页面顶部, 运行首个查询, 之后又运行第二个查询, 其余部分的第二个查询等 。 我的第一个查询效果不同... 我检查了$_ GET[ stone] 数字大于零, 低于所选择的最大值( StoneID), 但是如果有人手动将一个从库存中删除的石头放进StonID, 我仍然能得到错误 。 我修改了我的$_ GET 验证计划, 并将其移到包含的文件之上, 使页眉( ) 重新定向能够正常工作 。 现在, 我的第二个查询即使完全没有改变, 也不会成功 。

Var_dump($querySN) yields string(53) "select StoneName from stonetypes where StoneID = 1 " and var_dump($resultSN) yields NULL. It states: error occurred at line 35 --- $resultSN = $db->query($querySN); States several times: Couldn t fetch mysqli States a number of times: Property access is not allowed yet And states in conclusion: Call to a member function fetch_assoc() on a non-object on line 36---$rowSN = $resultSN->fetch_assoc();

有人知道这是怎么回事吗?

<?php 
require( ./inc/config.inc.php );

$stone = (INT)$_GET[ stone ];   

require(MYSQL1);

$queryCk = "select StoneID from stonetypes";
$resultCk = $db->query($queryCk);
$var = array();
while ($rowCk = $resultCk->fetch_assoc()){
     $var[] = $rowCk[ StoneID ];
}

if(!in_array($stone, $var)) {
     header( Location: beadgallery.php?type=stones );
     exit;
} else {


include( inc/header.inc.php );
include( inc/sidebar.inc.php );
include( inc/topMenuBar.inc.php );
include( inc/mainContentShell.inc.php );
?>

<div id="mainContent">
<div class="center">

<?php


             $querySN = "select StoneName from stonetypes where StoneID =  $stone  ";
             $resultSN = $db->query($querySN);
             $rowSN = $resultSN->fetch_assoc();

                echo  <table id="cartDisplayTable"> ;
                echo  <tr> ;
                echo  <td colspan="2"> ;
                        echo  <table id="titleTable"> ;
                        echo  <tr> ;
                            echo  <td id="stoneTitle"> ;
                            if (isset($rowSN[ StoneName ])){
                            echo  <h2> .ucwords($rowSN[ StoneName ]). </h2> ;}
                            echo  </td> ;
                        echo  </tr> ;

             $query = "select * from organized_inventory2 where StoneID =  $stone  ";
             $result = $db->query($query);

             $num_beadItems = $result->num_rows;
                $justused= abc ;
                for ($i=0; $i < $num_beadItems; $i++) {
                    $row = $result->fetch_assoc();

                    if (!isset($row[ itmphoto ])) {
                                    echo  </table> ;
                        echo  </td> ;
                        echo  </tr> ;

                        echo  <tr><td colspan="2"><hr id="cartDivider"></td></tr> ;

                        echo  <tr> ;
                        echo  <td id="cartImgCell"> ;
                        echo  <img src="img/nophoto.gif"> ;
                        echo  </td> ;
                        echo  <td id="cartInfoCell"> ;
                            echo  <table id="innerTable"> ;
                                    include ( inc/stoneCartInfo.inc.php );

                    } elseif ($row[ itmphoto ] == $justused) {
                                echo  <tr><td colspan="2"><hr id="itemDivider"></td></tr> ;
                                    include ( inc/stoneCartInfo.inc.php );

                    } else {

                                    echo  </table> ;
                        echo  </td> ;
                        echo  </tr> 
                        ;

                    echo  <tr><td colspan="2"><hr id="cartDivider"></td></tr> 
                    ;
                    echo  <tr> ;
                    echo  <td id="cartImgCell"> ;

                        echo  <img src="img/invent/ .$row[ itmphoto ]. "> ;
                        $justused = $row[ itmphoto ];

                        echo  </td> ;
                        echo  <td id="cartInfoCell"> ;
                            echo  <table id="innerTable"> ;
                                    include ( inc/stoneCartInfo.inc.php );                  }
                    }

                                    echo  </table> 
                                    ;
                        echo  </td> ;
                        echo  </tr> 
                        ;

                echo  </table> 
                ;
            } 
                 $result->free();
                 unset($result);
             $db->close();


        ?>

    </div> <!-- div class="center" -->

</div> <!-- div id="mainContent" -->
问题回答

整数并不需要引用数值, 如 < strong > StoneID = 1 , 这应该不会是一个问题, 因为 MySQL 应该打字 。

您没有检查“ $result” 包含什么内容, 如果它带有布尔值, 那么查询失败了, 您需要查看 < a href=" http:// php. net/ manual/ en/ mysqli. error. php " rel = "no follow" >mysqli_error 的输出 。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签