Jump to content

loop result showing twice


SVerheijen

Recommended Posts

echo '<table border="3">';
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
foreach($row as $field) {
echo '<td>'.$row.'</td>';
}
echo '</tr>';
}
echo '</table>';

my output shows all things twice. I found something on the internet with double loops or something. But i can't fix it! Can someone pls help?

Link to comment
Share on other sites

Yes and yes. I didn't say yours was wrong.  And yes, it is the field name, not the field value which I think is what the OP needs since he uses TD and not TH

 

I use that very type of code on my table row list pages to create dynamic tables.

 

Pulled from one of my pages...

foreach ($result as $row)
    {
    echo " <tr> \n";
    foreach ($row as $name => $value)
        {
        echo " <td>$value</td> \n";
        }
    echo " </tr> \n";  
    }
Edited by benanamen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.