0

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? Sorry if it repeated, but i have no idea to solve this!! Thank you!

1
  • Try the solution from Maarten van Middelaar. Commented Mar 12, 2014 at 22:45

2 Answers 2

2

Your SQL statement has no ORDER column:

$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.

Sign up to request clarification or add additional context in comments.

Comments

1

To add segarci,

$row = mysqli_fetch_array($sql) 

should be

$row = mysqli_fetch_array($user_query)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.