I have been trying to use the row count function which is part of the PDO’s.. i am using the for each loop to go thru a list of broken parts and then count how many of each part i need to order but using the code i put bellow its not working and im recving this error
“Fatal error: Call to a member function rowCount() on a non-object in W:\xampp\htdocs\ICT_Devices\damage_log\damage_parts_find.php on line 15”
Any help would be awesome my php is located just bellow here and i know that the pdo connect file and also the for each loop work but with the row count side im having issues
<?php
define('INCLUDE_CHECK',true);
require '../lib/connect/PDO_connect.php';
foreach($db->query("SELECT * FROM `damage_list`") as $damage_part) {
$parts=$damage_part['Damage'];
$stmt = $db->query('SELECT * FROM damage_log where damage=$parts');
$row_count = $stmt->rowCount();
echo $parts. "=".$row_count;
echo "<br>";
}
?>
Because when using single quote, variables will not be expanded.
So your query practically looks like:
Thus an error occurs, and
$stmtisFALSE.Use double quote may fix your problem.
Also, since you’re not quoting
$partsin your SQL statement, make sure$partsis always a number or any other types that do not need quoting.