This question already has answers here:
mysqli_num_rows() expects parameter 1 to be mysqli_result, object [duplicate]
(3 answers)
Closed 8 years ago.
Hello I am trying to look after content of Selected query... but however the error appears:
mysqli_num_rows() expects parameter 1 to be mysqli_result ...
$stmt= $this->conn->prepare("SELECT * FROM table") or die(mysql_error());
$result = $stmt->execute();
// check for empty result
if (mysqli_num_rows($result) > 0) {
..
}
EDIT
NEW ERROR mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in...
$stmt= $this->conn->prepare("SELECT * FROM table") or die(mysqli_error());
$stmt->execute();
$stmt->store_result();
// check for empty result
if ($stmt->num_rows > 0) {
// looping through all results
$response["array"] = array();
while ($row = mysqli_fetch_array($stmt)) {
... }
I think I got it:
while ($row = $stmt->fetchAll()) {
// temp user array
$array= array();
$array["bla"] = $row["bla"];
... }
but I get only "null" as value...?
EDIT
Now i got it:
$stmt->bind_result($column1, $column2...)
then
$array["bla"] = $column1;
$array["bla2"] = $column2;
but isn't it possible to bind_result all colums without to put every single one into a variable?
or isnt it possible to use this :
$array["bla"] = $row["bla"];
so it puts the value from the row with the column "bla" into $array[bla]?
because the way i solved it, seems to be veyr difficult
Correct is
$stmt= $this->conn->prepare("SELECT * FROM table") or die(mysql_error());
$result = $stmt->execute();
$result->store_result();
// check for empty result
if ($result->num_rows > 0) {
..
}
Related
I'm trying to echo out every single thing in a table from sql, my code is as follows
$stmt = $link->prepare("SELECT * FROM articles");
$stmt->execute();
$stmt->store_result();
if (mysqli_stmt_num_rows($stmt) >= 1) {
$result = mysqli_stmt_get_result($stmt); //get result object
while ($row = mysqli_fetch_assoc($result)){ //get associative array
$news = $row['title'];
}
}
It doesn't work, returning as mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given
I've done my research but literally nothing works :(
You don't need to use prepared statements for this SELECT query as you aren't specifying anything WHERE.
$query = 'SELECT * FROM articles';
if ($result = $link->query($query)) {
while ($row = $result->fetch_assoc()) {
$news = $row['title'];
}
}
For a really good in-depth answer check this out: https://stackoverflow.com/a/11575617/1427345
This question already has an answer here:
mysqli_num_rows() expects parameter 1 to be mysqli_result, array given
(1 answer)
Closed 1 year ago.
How can I fix this error?
$qry = "select id,pwd,username from users where username='jimmy'";
$res = mysqli_query($conn,$qry);
$row = mysqli_fetch_array($res);
$count = mysqli_num_rows($row); // if uname/pass correct it returns must be 1 row
As the error says the parameter should be a mysqli_result object. So use the returned value from your mysqli_query() call
$res=mysqli_query($conn,$qry);
$count = mysqli_num_rows($res);
// ^^^^
$row=mysqli_fetch_array($res);
this is the problem
$count = mysqli_num_rows($row);
this should be
$count = mysqli_num_rows($res);
This question already has answers here:
mysql_num_rows() expects parameter 1 to be resource, boolean given in [duplicate]
(2 answers)
Closed 7 years ago.
I am trying to send userid and otp which is entered in an edittext in an android app but from server side i get following response.
mysql_num_rows() expects parameter 1 to be resource, boolean given in
/nfs/c07/h02/mnt/111018/domains/surun.co/html/demo/rest/api.php
on line 168
line no 168 from php code
if(mysql_num_rows($results) > 0)
The php code in more details follows:
public function selectQuery($table_name,$fields,$where="",$show = 0)
{
$i =0;
if($where == "")
$sql = "SELECT ".$fields." FROM ".$table_name;
else
$sql = "SELECT ".$fields." FROM ".$table_name." WHERE ".$where;
//MySqli Select Query
if($show == 1)
return $sql;
$results = mysql_query( $sql,$this->db );
if(mysql_num_rows($results) > 0)
{
while($row = mysql_fetch_assoc($results))
{
$result[$i++]= $row;
}
}
return $result;
}
Read this link and apply these changes How could I change this mysql to mysqli? while also adding error checking in the form of
$results = mysqli_query($this->db, $sql) or die (mysqli_error($connection));
(or for MySQL just use $results = mysqli_query($sql,$this->db) or die (mysql_error()); )
What you currently have is that your $this->db value is not connecting the database properly or you have a syntax error in your WHERE clause.
This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 2 years ago.
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!
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.
To add segarci,
$row = mysqli_fetch_array($sql)
should be
$row = mysqli_fetch_array($user_query)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given
I am getting the following error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource
My query seems fine, here is my code:
function products()
{
$query = "SELECT id, quantity, price FROM dvd WHERE quantity > 0";
if (!$query)
{
echo "no product found";
die(mysql_error());
}
else
{
while ($query_row = mysql_fetch_assoc($query)){
echo "Test";
}
}
}
What does that error mean?
you forgot to execute the query:
mysql_query($query);
$query is just the text of the query. Change it to:
$query=mysql_query("SELECT id, quantity, price FROM dvd WHERE quantity > 0");
You forgot to call mysql_query() which actually executes it.
Replace the $query = ...; line with this:
$query = mysql_query("SELECT id, quantity, price FROM dvd WHERE quantity > 0");
You need to get a result from the query first...
$result = mysql_query($query);
... Then pass $result to mysql_fetch_assoc()
mysql_fetch_assoc($result);