I consistently miss the first row result, which is more noticeable when there is only one row result.
I have a problem with my PDO commands. Any suggestions for how to correct please? If I remove the $pod->prepare nothing works. Not sure what to do?
<?php
$sql = "SELECT * FROM Order_Items
JOIN Parts ON Parts.id = Order_Items.part_id
WHERE Order_Items.orders_id = $id
AND qty <> 0
ORDER BY Parts.id";
$q = $pdo->prepare($sql);
$q->execute(array());
$row = $q->fetch(PDO::FETCH_ASSOC); // Roy says this is not needed
while ($row = $q->fetch(PDO::FETCH_ASSOC))
{
echo '<tr>';
echo '<td>' . $row['part_num'] . '</td>';
echo '<td>' . $row['part_desc'] . '</td>';
echo '<td>' . $row['qty'] . '</td>';
}
Database::disconnect();
?>
You are duplicating $row = $q->fetch(PDO::FETCH_ASSOC);.
When you asing $q to $row, $q->fetch is cleared (with no data) so in the IF sentence you have no rows to fetch in $q.
You have to remove $row = $q->fetch(PDO::FETCH_ASSOC); and just use it in the IF.
Also try to do a fetchAll() to $q.
$result = $query -> fetchAll();
foreach( $result as $row ) {
/*CODE*/
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With