Hi All,
I have a script which first runs a query, then runs another one to count how many queries are returned.
Question I have is am I making life hard for myself. Could this be rolled into one query?:
//SELECT DATA
$SEARCH_QUERY = "SELECT * FROM tbl";
$RES = $dbc->query($SEARCH_QUERY);
$name = $RES['name'];
$age = $RES['age'];
//COUNT DATA
$COUNT_QUERY = $dbc->query("SELECT COUNT(*) AS total FROM tbl");
$COUNT_QUERY->setFetchMode(PDO::FETCH_ASSOC);
$ROW = $COUNT_QUERY->fetch();
$TOTALROWS = $ROW['total'];
// If no results in the database:
if($TOTALROWS == 0) {
echo $NUM_RES = 'Sorry, we have found no people in the database';
} else {
echo 'We have found '.$NUM_RES.' people in the database';
}