开发者

PDO Row Count Output

开发者 https://www.devze.com 2023-03-29 04:20 出处:网络
In the following attempting to get the total rows for the query, as rowCount does not function with mySQL, what solutions could spare me another hour of experiments:

In the following attempting to get the total rows for the query, as rowCount does not function with mySQL, what solutions could spare me another hour of experiments:

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>';

            }

My goal is displaying output here:

// 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>

---------Complete Script----------

<?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开发者_如何学C 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');
?>


Try this:

$DBH->query($sql);
$foundRows = $DBH->query("SELECT FOUND_ROWS()")->fetchColumn();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号