Reputation: 163
i am getting the "$field_value" twice - but why?
normal the structure is: <id><name><address><email>
but now i get <id><id><name><name><address><address><email><email>
here is the code:
<tbody>
<?php
$STH = $DBH->prepare("SELECT * FROM kunden");
$STH->execute();
$result = $STH->fetchall();
foreach($result as $key => $inner_arr) {
echo '<tr>';
foreach($inner_arr as $field_name => $field_value) {
echo "<td>{$field_value}</td>";
}
echo '</tr>';
}
?>
</tbody>
Upvotes: 0
Views: 781
Reputation: 160993
You need to set the fetchMode
:
Default is PDO::FETCH_BOTH
, so an array indexed by both column name and number will be returned.
$result = $STH->fetchall(PDO::FETCH_ASSOC);
Upvotes: 6