There is such a piece of code, how to take the number of result sets .... Please take a look at the great God ...
$stmt = $dbc->prepare (' Select COUNT (*) from Loginlog ');
$rows = $stmt->execute ();
Pagedivide ($rows, 10);
$result = $dbc->prepare (' select * from Loginlog ORDER BY logintime desc limit $sqlfirst, $shownu ');
$result->execute ();
Echo ' A total '. $rows. ' Log in ';
Echo ';
Echo ';
Echo ';
Echo '
'; Echo '
'; Echo '
user name | '; echo '
password | '; Echo '
login IP | '; Echo '
login time | '; Echo '
login status | '; Echo '
number of attempts | '; Echo '
online status | '; Echo '
'; while ($row = $result->fetch ()) {echo '
'; Echo '
'. $row [' name ']. ' | '; Echo '
'. $row [' Password ']. ' | '; Echo '
'. $row [' IP ']. ' | '; Echo '
'. $row [' Logintime ']. ' | '; Echo '
'. $row [' status ']. ' | '; Echo '
'.' 1 '. ' | '; Echo '
'.' Online '. ' | '; Echo '
'; } Echo '
';
Echo '';
Echo ';
Echo ';
Echo ';
Reply to discussion (solution)
$result = $stmt->fetch (pdo::fetch_num);
echo $result [0]; This is
$result = $stmt->fetch (pdo::fetch_num);
echo $result [0]; This is
Is that how it is written?
$stmt = $dbc->prepare (' select * from Loginlog ');
$rows = $stmt->execute ();
$rowsNum = $rows->fetch (pdo::fetch_num);
LZ should be $stmt= $dbc->prepare (' select * from Loginlog ');
$rows = $stmt->execute ();
$rowsNum = $rows->fetch (PDO::FETCH_ASSOC);
Print_r ($rowsNum->rowcount ());
LZ should be $stmt= $dbc->prepare (' select * from Loginlog ');
$rows = $stmt->query ();
$rowsNum = $rows->fetch (PDO::FETCH_ASSOC);
Print_r ($rowsNum->rowcount ());
There is a small problem above, is Print_r ($rows->rowcount ());
LZ should be $stmt= $dbc->prepare (' select * from Loginlog ');
$rows = $stmt->query ();
$rowsNum = $rows->fetch (PDO::FETCH_ASSOC);
Print_r ($rowsNum->rowcount ());
There is a small problem above, is Print_r ($rows->rowcount ());
Fatal Error:call to a member function fetch () on a non-object I
$stmt = $dbc->prepare (' select * from Loginlog ');
$rows = $stmt->execute ();
$rowsNum = $rows->fetch (PDO::FETCH_ASSOC);
$rowsN = $rows->rowcount ();
$stmt = $dbc->prepare (' select * from Loginlog ');
$rows = $stmt->execute ();
$rowsNum = $stmt->fetch (pdo::fetch_num);
$stmt = $dbc->prepare (' select * from Loginlog ');
$rows = $stmt->execute ();
$rowsNum = $stmt->fetch (pdo::fetch_num);
Echo an array ... Want to rowcount ();
$stmt = $dbc->prepare (' Select COUNT (*) from Loginlog ');
$stmt->execute ();
$rowsNum = $stmt->fetch (pdo::fetch_num); Returns an array
Print_r ($rowsNum);
or this:
$stmt = $dbc->prepare (' Select COUNT (*) from Loginlog ');
$stmt->execute ();
$rowsNum = $stmt->fetchcolumn ();
Echo $rowsNum;
int Pdostatement::rowcount (void)
Pdostatement::rowcount () returns the number of rows affected by the previous delete, INSERT, or UPDATE statement executed by the corresponding Pdostatement object.
If the previous SQL statement executed by the related pdostatement is a SELECT statement, some data may return the number of rows returned by this statement. However, this approach does not guarantee that all data is valid and should not be relied upon for portable applications.
$stmt = $dbc->prepare (' Select COUNT (*) from Loginlog ');
$stmt->execute ();
$rowsNum = $stmt->fetch (pdo::fetch_num); Returns an array
Print_r ($rowsNum);
or this:
$stmt = $dbc->prepare (' Select COUNT (*) from Loginlog ');
$stmt->execute ();
$rowsNum = $stmt->fetchcolumn ();
Echo $rowsNum;
$stmt = $dbc->prepare (' Select COUNT (*) from Loginlog ');
$rows = $stmt->execute ();
$rowsNum = $rows->fetchcolumn ();
Pagedivide ($rowsNum, 10);
$result = $dbc->prepare (' select * from Loginlog ORDER BY logintime desc limit $sqlfirst, $shownu ');
$result->execute ();
if ($stmt) {
/* $result =mysql_query (' select * from Loginlog ORDER by logintime Desc ');
$total =mysql_num_rows ($result);
Pagedivide ($total, 10);
$result =mysql_query ("SELECT * from Loginlog ORDER BY logintime desc limit $sqlfirst, $shownu"); */
Echo ' A total '. $rowsNum. ' Log in ';
Echo ';
Echo ';
Echo ';
Echo '
'; Echo '
'; Echo '
user name | '; echo '
password | '; Echo '
login IP | '; Echo '
login time | '; Echo '
login status | '; Echo '
number of attempts | '; Echo '
online status | '; Echo '
'; while ($tota =mysql_fetch_assoc ($result)) {while ($row = $result->fetch ()) {echo '
'; Echo '
'. $row [' name ']. ' | '; Echo '
'. $row [' Password ']. ' | '; Echo '
'. $row [' IP ']. ' | '; Echo '
'. $row [' Logintime ']. ' | '; Echo '
'. $row [' status ']. ' | '; Echo '
'.' 1 '. ' | '; Echo '
'.' Online '. ' | '; Echo '
'; } Echo '
';
Echo '';
Echo ';
Echo ';
Echo ';
The code as a whole is like this, but the page is always error
Fatal Error:call to a member function Fetchcolumn () on a non-object why is this?
$rows = $stmt->execute ();
$rowsNum = $stmt->fetchcolumn ();
$rows = $stmt->execute ();
$rowsNum = $stmt->fetchcolumn ();
$stmt = $dbc->prepare (' Select COUNT (*) from Loginlog ');
$rows = $stmt->execute ();
$rowsNum = $rows->fetchcolumn ();
That's what it says. Error ~
This post was last edited by xuzuning on 2013-06-26 15:38:19
$stmt->execute ();
$rowsNum = $stmt->fetchcolumn ();
$stmt->execute ();
$rowsNum = $stmt->fetchcolumn ();
Yes, well, that's right. Thank you, can you tell me why? I'll avoid making such a mistake later.
PDO::p Repare Returns a Pdostatement object, which is your $stmt
Pdostatement::execute returns a logical value that indicates whether the execution was successful or not.
If you write $rows = $stmt->execute ();
So $rows just a true
Of course there is no Fetchcolumn method, so the error.
One is to read the manual, not only to see the usage, but also to learn to look at the prototype statement
The second is to learn to read the wrong message
PDO::p Repare Returns a Pdostatement object, which is your $stmt
Pdostatement::execute returns a logical value that indicates whether the execution was successful or not.
If you write $rows = $stmt->execute ();
So $rows just a true
Of course there is no Fetchcolumn method, so the error.
One is to read the manual, not only to see the usage, but also to learn to look at the prototype statement
The second is to learn to read the wrong message
Well, I understand, thank you. I have been the project-driven way to learn PHP, encountered problems before going through the manual ...