Why doesn't my PHP function work as expected?

For loop in php prints everything twice?

  • i have a table with single value, yet when i write the below code it repeats twice value1 value1 value2 value2 value3 value3 anyone any idea what is wrong... i know i can use extract() function but want to know why it doesnt work for foreach while($row = mysql_fetch_array($results)) { echo "<tr>\n"; foreach($row as $value) { echo "<td>\n"; echo $value; echo "</td>\n"; } echo "</tr>\n"; }

  • Answer:

    You have a while AND a for! Rewrite it this way: while ( $row = mysql_fetch_array ($results) ) { echo "<tr> \r\n"; echo $row [ 0 ] ; echo "</td> \r\n"; } (Spaces added)

BenBot at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.