在下面尝试获取查询的总行数时,由于rowCount不能与mySQL一起运行,有什么解决方案可以让我再花一小时的实验:
foreach($DBH->query($sql) as $row){
//want the total $row count for output:
echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['dr'] . '</td></tr>';
}
我的目标是在这里显示输出:
// Table header.
echo <<<EOT
<table class="app_table" summary="The Current roster of users registered in our application.">
<caption>The Current Registered Users:'<?php echo("count"); ?>'//Display total count
<span id="summaryView"></span></caption>
<thead>
<tr>
---------完整的脚本----------
<?php
$page_title = 'View the Current Users';
include ('./inc/header.php');
// Page header:
echo '<h1>Registered Users</h1>';
require_once ('../pdo_connect.php'); // Connect to the db.
// Make the query:
$sql = "SELECT CONCAT(last_name, ', ', first_name) AS name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC";
// Table header.
echo <<<EOT
<table class="app_table" summary="The Current roster of users registered in our application.">
<caption>The Current Registered Users:'<?php echo("12"); ?>' <span id="summaryView"></span></caption>
<thead>
<tr>
<th class="Corner">Name</th>
<th>Date Registred</th>
</tr>
</thead>
<tbody>
EOT;
try {
foreach($DBH->query($sql) as $row){
echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['dr'] . '</td></tr>';
}
echo '</tbody></table>'; // Close the table.
// $DBH = null;//using a persistant connect see php.net
} catch (PDOException $e){
echo'<p class="error">' . "Error!: " . $e->getMessage() . '</p>';
die();
}
include ('./inc/footer.php');
?>
答案 0 :(得分:1)
试试这个:
$DBH->query($sql);
$foundRows = $DBH->query("SELECT FOUND_ROWS()")->fetchColumn();