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>"; } ?>
$partswithin the loop then executing the query. Also, if you're only after a rowcount, useSELECT COUNT(1)instead. It will perform better and be more compatible across database engines