简体   繁体   English

Mysqli num行和mysqli获取数组问题

[英]Mysqli num rows and mysqli fetch array issue

I try to google it but, i really dont understand what is the problem with this query. 我尝试用谷歌搜索,但是,我真的不明白这个查询有什么问题。 Here is code 这是代码

include_once("includes/db_connection.php");
//Upit za prikaz pitanja!
$listaPitanja = "";
$sql = "SELECT id, username, question FROM useroptions ORDER BY DESC";
$user_query = mysqli_query($db_connection, $sql);
$pitanjaCount = mysqli_num_rows($user_query); //line 8
if ($pitanjaCount > 0) {
while ($row = mysqli_fetch_array($sql))  { //line 10
$id = $row['id'];
$question = $row['question'];
$username = $row['username'];
$listaPitanja .= '<div id="brojOdgovora">'.$id.'</div>
            <div id="tekstPitanja"><h3>'.$question.'</h3></div>
            <div id="userPitanja"><h6>'.$username.'</h6></div>';
    } 
} else {
$listaPitanja = "There is no inserted questions!";
}

This query gives me nothing. 这个查询给我什么。 Just this error mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in something on line 8, and if i delete ORDER BY DESC there is some error on line 10? 只是这个错误mysqli_num_rows()期望参数1为mysqli_result,在第8行的某些内容中给出布尔值,如果我删除ORDER BY DESC ,则在第10行有一些错误吗? Sorry if it repeated, but i have no idea to solve this!! 对不起,如果它重复了,但是我不知道要解决这个问题! Thank you! 谢谢!

Your SQL statement has no ORDER column: 您的SQL语句没有ORDER列:

$sql = "SELECT id, username, question FROM useroptions ORDER BY DESC";

Change it with the correct column name: 用正确的列名更改它:

$sql = "SELECT id, username, question FROM useroptions ORDER BY column_name DESC";

Probably, mysqli_query is returning false instead of mysqli_result object. 可能是, mysqli_query返回的是false而不是mysqli_result对象。

To add segarci, 要添加segarci,

$row = mysqli_fetch_array($sql) 

should be 应该

$row = mysqli_fetch_array($user_query)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM