For () displays $ row_record [] once, and $ message $ i times - PHP

$RecordCount=mysql_num_rows($pnname); 

for($el=1; $el<=$RecordCount;$el++) {
$message .= "test--test";

echo $el."--".$row_pnname01['pnom']."<BR>";
echo $message."<BR>";


}

The number of samples is $messagedisplayed here $i, i.e. if $i= 5 is $messagedisplayed 5 times, but is $row_pnname01['pnom']displayed only once for each $iaccount.

Any idea on why this is happening. Of course, something that I must have forgotten.

Thanks jean

+3
source share
2 answers

Instead of this

$message .= "test--test";

Do it

$message = "test--test";
+3
source
$RecordCount=mysql_num_rows($pnname); 

for ($el=1; $el<=$RecordCount;$el++) {
  $message = "test--test";

  echo $el."--".$row_pnname01['pnom']."<BR>";
  echo $message."<BR>";
}

That should do the trick. $message .= "test--test";continues to add the string "test-test" to the variable $message. When using =, do not .=just assign a new value $message.

0
source

All Articles