Reputation: 195
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>";
}
?>
Upvotes: 1
Views: 481
Reputation: 1173
The error message is telling you $stmt is not an object.
This is likely because your query is bad ... the $parts
is not interpreted inside single quotes, and is thus in the query literally.
Upvotes: 0
Reputation: 10070
Because when using single quote, variables will not be expanded.
So your query practically looks like:
SELECT * FROM damage_log where damage=$parts
Thus an error occurs, and $stmt
is FALSE
.
Use double quote may fix your problem.
Also, since you're not quoting $parts
in your SQL statement, make sure $parts
is always a number or any other types that do not need quoting.
Upvotes: 1