PHP/sqlite3 rowcount question - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: PHP/sqlite3 rowcount question (
/showthread.php?tid=650259)
PHP/sqlite3 rowcount question -
jasperschellekens - 24.02.2018
Hello there,
I know this is not really pawn. But it is pawn related.
I am creating a user control panel and i want to list reports on the website for admins.
This code works perfect but i have trouble with page navigation.
If i use the same way as in samp like count++ it always returns 1.
How do i succesfully count rows? because numrows and sqlite_num_rows dont work.
PHP код:
$record_index= ($page-1) * $limit;
$sql = "SELECT * FROM REPORTS LIMIT $record_index, $limit";
$stmt = $db->query($sql);
while($row = $stmt->fetchArray(SQLITE3_ASSOC) )
{
$countrows = $stmt->numRows(); // error
I did try to follow these :
http://php.net/manual/en/function.sqlite-num-rows.php
But this always result into a fatal error
Код:
Fatal error: Call to undefined method SQLite3Result::numRows() in D:\AppServ\www\ucp\reports.php on
Any help would be appreciated
Re: PHP/sqlite3 rowcount question -
jasperschellekens - 24.02.2018
I have fixed it fortunately.
If you may run into this problem. This is a fix:
PHP код:
<?php
function SqliteNumRows($query){
$numRows = 0;
while($rows = $query->fetchArray()){
++$numRows;
}
return $numRows;
}
?>
$countrows = SqliteNumRows($stmt);
//edit: Otherwise it shows 4 instead of 5 when having 5 rows.
$countrows += 1;
Re: PHP/sqlite3 rowcount question -
kingmk - 24.02.2018
Quote:
Originally Posted by jasperschellekens
I have fixed it fortunately.
If you may run into this problem. This is a fix:
PHP код:
<?php
function SqliteNumRows($query){
$numRows = 0;
while($rows = $query->fetchArray()){
++$numRows;
}
return $numRows;
}
?>
$countrows = SqliteNumRows($stmt);
|
did u try this?
PHP код:
while($row = $stmt ->fetch_object())
{
$countrows = $row->num_rows;
I know u fixed it, but i wanna know if this works/fixes it also.
Re: PHP/sqlite3 rowcount question -
jasperschellekens - 24.02.2018
Quote:
Originally Posted by kingmk
did u try this?
PHP код:
while($row = $stmt ->fetch_object())
{
$countrows = $row->num_rows;
I know u fixed it, but i wanna know if this works/fixes it also.
|
I don't think so but im not sure. i use $row = $stmt->fetchArray(SQLITE3_ASSOC); to fetch in this case.
Also my way didnt exactly fix it.
When you have 5 rows it shows 4.
So to actually fix it now it must be:
PHP код:
$countrows = SqliteNumRows($stmt);
$countrows += 1;
Re: PHP/sqlite3 rowcount question -
jasperschellekens - 24.02.2018
Quote:
Originally Posted by ******
PHP код:
SELECT COUNT(*) FROM `reports`;
|
will also return 1 in sqlite/php.