This question already has answers here:
Fatal error: Call to undefined function mysqli_result()
(2 answers)
Closed 6 years ago.
I have problem with mysqli_result() -> (ex mysql_result)
My code:
$per_page = 6;
$pages_query = mysqli_query($conn, 'SELECT COUNT(id) FROM users');
$pages = ceil(mysqli_result($pages_query, 0) / $per_page);
browser error:
Fatal error: Call to undefined function mysqli_result() in /Applications/MAMP/htdocs/bootstrap/pagination.php on line 11
As opposed to mysql_result(), there's no mysqli_result() function available in MySQLi.
Use mysqli_fetch_array() function to get the total number of rows. Your code should be like this:
$per_page = 6;
$pages_query = mysqli_query($conn, 'SELECT COUNT(id) FROM users');
$row = mysqli_fetch_array($pages_query);
$pages = ceil($row[0] / $per_page);
Related
This question already has answers here:
How to fetch all in assoc array from a prepared statement?
(4 answers)
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 am trying to fetch TaxRate data from a table and I'm trying to select the first array only. However, I keep getting this error
"Fatal error: Uncaught Error: Call to a member function fetch_array()
on boolean in C:\xampp\htdocs\flowerique\shoppingCart.php:77 Stack
trace: #0 {main} thrown in C:\xampp\htdocs\flowerique\shoppingCart.php
on line 77"
Does anyone know the cause of this error and how do I fix it? Thanks!
This is my code :
//Retrieve Current GST Pricing
$qry = "SELECT * FROM gst GROUP BY EffectiveDate DESC";
$stmt = $conn->prepare($qry);
$stmt->execute();
//$stmt->close();
$result = $conn->query($qry);
$row = $result->fetch_array(); // This is line 77
while($row["EffectiveDate"] < date("Y-m-d"))
{
$row = $result->fetch_array();
}
$currentTaxRate = $row["TaxRate"];
This question already has answers here:
Call to undefined method mysqli_stmt::get_result
(10 answers)
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 4 years ago.
Error: Uncaught Error: Call to undefined method mysqli_stmt::get_result()
How to use it right?
public static function login($benutzername, $passwort){
$result = Connection::getInstance()->db;
$sql = 'SELECT * FROM users WHERE benutzername = ? AND passwort = ?';
$stmt = $result->prepare($sql);
$passwort = md5($passwort);
maybe use mysqli-stmt.bind-result ?
$stmt->bind_param('ss', $benutzername, $passwort);
$stmt->execute();
$result = $stmt->get_result();
or mysqli_stmt_fetch?
if ($result->num_rows != '0') {}
Thanks a lot!
This question already has an answer here:
Call to undefined function mysqli_result::num_rows()
(1 answer)
Closed 6 years ago.
Alright so I am getting an error that there is no function called num_rows for some reason, anyone knows why?
$result = $sql->query("SELECT * FROM private_messages WHERE sender='".$this->getUsername()."' LIMIT $page_count,5");
$count = $result->num_rows();
Fatal error: Call to undefined method mysqli_result::num_rows()
I attemped to search for the problem online but couldnt find any successful results regarding this issue.
There's no num_rows method in MySQLi_Result. Check MySQLi_Result up in PHP's documentation: http://php.net/manual/pt_BR/class.mysqli-result.php
Perhaps you mean mysqli_num_rows static method or even the num_rows property (in which case you should use without the parenthesis):
$result = $sql->query("SELECT * FROM private_messages WHERE sender='".$this->getUsername()."' LIMIT $page_count,5");
$count = $result->num_rows;
Because its not a method. Its a variable. From the docs,
Object oriented style
int $mysqli_result->num_rows;
So in your case, you should do
$result = $sql->query("SELECT * FROM private_messages WHERE sender='".$this->getUsername()."' LIMIT $page_count,5");
$count = $result->num_rows;
This question already has answers here:
pdo - Call to a member function prepare() on a non-object [duplicate]
(8 answers)
Closed 6 years ago.
I tried to add a section to IMPORT infos from a form into a db table and I get this error:
Fatal error: Call to a member function prepare() on a non-object in /srv/disk7/2173760/www/site.net/admin.php on line 79
and this is the code I tried to use:
<?php
$pdo = new PDO('mysql:host=;dbname=', '', '');
$sql = "SELECT * FROM games LIMIT 10";
foreach ($pdo->query($sql) as $row) {
if(isset($_POST['insert']))
{
$game_title=$_POST['gtitle'];
$yt_id=$_POST['ytlink'];
$name=$_POST['gtitle'];
$source=$_POST['slink'];
$url=$_POST['keysl'];
$steam_id=$_POST['appid'];
$categories=$_POST['inlineRadioOptions'];
$query_ins="INSERT INTO tbl_games(ytlink,gtitle,slink,keysl,appid,keysleft) VALUES(:yt_id,:name,:source,:url,:steam_id,:categories)";
$stmt_query=$dbh->prepare($query_ins);
$games_ins=$stmt_query->execute(array(":yt_id"=>$ytlink,":name"=>$gtitle,":source"=>$slink,":url"=>$keysl,":steam_id"=>$appid,":categories"=>$keysleft));
if(!$games_ins)
{
$error=$stmt_query->errorInfo();
echo $error['2'];
}
}
?>
this is line 79:
$stmt_query=$dbh->prepare($query_ins);
I replaced with this and still don't working..
<?php
$pdo = new PDO('mysql:host=;dbname=', '', '');
$sql = "SELECT * FROM games LIMIT 10";
foreach ($pdo->query($sql) as $row) {
$query = "INSERT INTO tbl_games(yt_id,name,url,source,keysleft,steam_id)".
"SELECT ytlink,gtitle,slink,keysl,appid FROM games LIMIT 10"
?>
You have to instantiate $dbh before use it, like you've done with $pdo.
Why don't you use the object $pdo from the second line instead?
This question already has answers here:
Fatal error: Call to a member function fetch_assoc() on a non-object [duplicate]
(4 answers)
Closed 7 years ago.
<?php $results = DB::select('select * from insurance_policy where Id = ?', [1]);
$row = $results->fetch_assoc();
echo $row["Amount"];
?>
Here is my code it is giving me a error:Call to a member function fetch_assoc() on a non-object.
I am using Laravel 5
DB::select would return an Array which stores the DB rows.
You can iterate the results
foreach ($results as $row) { echo $row['Amount']; }