亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么mysqli num_rows總是返回0?

為什么mysqli num_rows總是返回0?

絕地無雙 2019-11-04 09:32:26
我一直在獲取要使用mysqli返回的行數方面遇到麻煩。即使確實有一些結果,我每次都會得到0。if($stmt = $mysqli->prepare("SELECT id, title, visible, parent_id FROM content WHERE parent_id = ? ORDER BY page_order ASC;")){      $stmt->bind_param('s', $data->id);      $stmt->execute();    $num_of_rows = $stmt->num_rows;      $stmt->bind_result($child_id, $child_title, $child_visible, $child_parent);      while($stmt->fetch()){        //code    }    echo($num_of_rows);    $stmt->close();}為什么沒有顯示正確的數字?
查看完整描述

3 回答

?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

您需要先調用MySqli_Stmt::store_result()num_rows查找:


if($stmt = $mysqli->prepare("SELECT id, title, visible, parent_id FROM content WHERE parent_id = ? ORDER BY page_order ASC;")){  

    $stmt->bind_param('s', $data->id);  

    $stmt->execute();

    $stmt->store_result(); <-- This needs to be called here!

    $num_of_rows = $stmt->num_rows;  

    $stmt->bind_result($child_id, $child_title, $child_visible, $child_parent);  


    while($stmt->fetch()){

        //code

    }


    echo($num_of_rows);


    $stmt->close();

}

請參閱上的文檔MySQLi_Stmt->num_rows,該文檔顯示在頁面頂部附近(在主要說明區域中)...


查看完整回答
反對 回復 2019-11-04
?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

嘗試$num_of_rows在if(statement)之后-在bind_param之前設置您的權限...除非那會改變您的結果。沒有更多信息很難說。


查看完整回答
反對 回復 2019-11-04
?
素胚勾勒不出你

TA貢獻1827條經驗 獲得超9個贊

您的查詢似乎出了點問題。嘗試進行直接查詢,例如if($stmt = $mysqli->query("SELECT id, title, visible, parent_id FROM content WHERE parent_id = YOURIDHERE ORDER BY page_order ASC;")){,看看是否仍然可以解決0個結果

查看完整回答
反對 回復 2019-11-04
  • 3 回答
  • 0 關注
  • 983 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號