Duplicated mysql results on a dynamic php table

Hello everyone.

I’m having this issue, I get duplicated columns when I try to display the results from a mysql table using pdo_mysql.

Here’s the code:

[php]

<?php $user = "******"; $pass = "*******************"; $dbh = new PDO('mysql:host=***.***.***.***;dbname=*****', $user, $pass); ?> <?php foreach($dbh->query('SELECT * FROM romx_gmitemlog') as $row) { echo ''; foreach ($row as $col) { echo ''; } echo ''; }

?>

column1 column2 column3 column4 column5 column6
'; echo $col; echo '

[/php]

I’m getting something like this.
[table]
[tr]
[td]column1[/td][td]column2[/td][td]column3[/td][td]column4[/td][td]column5[/td][td]column6[/td]
[/tr]
[tr]
[td]result1[/td][td]result1[/td][td]result2[/td][td]result2[/td][td]result3[/td][td]result3[/td][td]result4[/td][td]result4[/td][td]result5[/td][td]result5[/td][td]result6[/td][td]result6[/td]
[/tr]
[/table]

I’ve been struggling with this for hours, googled a lot and found nothing yet. I’d so much appreciate any help!

I am not familiar with pdo_mysql, but you can try to debug this code. On the first iteration of outer foreach loop try to add this to see if problem is with query result:
[php]
echo ‘

’;
print_r($row);
echo ‘
’;
[/php]

Also, I would change code to eliminate query from foreach statement, like this:
[php]
$r = $dbh->query(‘SELECT * FROM romx_gmitemlog’);
foreach($r as $row) {
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service