SVerheijen Posted September 9, 2016 Share Posted September 9, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/302121-loop-result-showing-twice/ Share on other sites More sharing options...
Jacques1 Posted September 9, 2016 Share Posted September 9, 2016 (edited) You're always printing $row in your inner loop. The output should actually be complete nonsense like “Array Array Array ...”. Edited September 9, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/302121-loop-result-showing-twice/#findComment-1537226 Share on other sites More sharing options...
cyberRobot Posted September 9, 2016 Share Posted September 9, 2016 my output shows all things twice. I found something on the internet with double loops or something. Did you post your code or the thing you found on the internet? It will be easier to help if we see the problem code. Quote Link to comment https://forums.phpfreaks.com/topic/302121-loop-result-showing-twice/#findComment-1537228 Share on other sites More sharing options...
ginerjm Posted September 9, 2016 Share Posted September 9, 2016 You could do this instead: echo "<td>$field</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/302121-loop-result-showing-twice/#findComment-1537233 Share on other sites More sharing options...
benanamen Posted September 9, 2016 Share Posted September 9, 2016 <table> <?php $row = mysqli_fetch_assoc($result); foreach ($row as $field) { echo "<tr><td>$field['field_name']</td></tr>"; } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/302121-loop-result-showing-twice/#findComment-1537244 Share on other sites More sharing options...
ginerjm Posted September 9, 2016 Share Posted September 9, 2016 No - I think my example is correct. $field IS the field name Quote Link to comment https://forums.phpfreaks.com/topic/302121-loop-result-showing-twice/#findComment-1537249 Share on other sites More sharing options...
benanamen Posted September 9, 2016 Share Posted September 9, 2016 (edited) 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 September 9, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302121-loop-result-showing-twice/#findComment-1537250 Share on other sites More sharing options...
ginerjm Posted September 9, 2016 Share Posted September 9, 2016 The op was using $row which is the Array and not any contents of the array. Quote Link to comment https://forums.phpfreaks.com/topic/302121-loop-result-showing-twice/#findComment-1537251 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.