Making WHILE to a variable

[b]code[/b]

$testResult=mysql_query("select id, name from myTable order by id ") ; 

while($row = mysql_fetch_array($testResult))
{

$myRecord="(". $row['id'].")".$row['name']." <br>";

echo $myRecord;

}


[b]result[/b]

[COLOR="#0000CD"](id) name[/COLOR]

(1)  Tom 
(2)  Mary 
(3)  Jane 
(4)  Jack

The code above produces the result above.

I like to get the same result above by using one variable named “myWholeResult”.

The code below which is one of trial for it doesn’t work correctly, but I hope it shows what I want.

[b]trial code[/b]

$testResult=mysql_query("select id, name from myTable order by id ") ; 


[COLOR="#FF0000"]$myWholeResult[/COLOR] = while($row = mysql_fetch_array($testResult))
{

$myRecord="(". $row['id'].")".$row['name']." <br>";

echo $myRecord;

};

echo [COLOR="#FF0000"]$myWholeResult[/COLOR];

[b]target result[/b]

(1)  Tom 
(2)  Mary 
(3)  Jane 
(4)  Jack

The trial code2 below can get what I want with A variable, but I guess there might be easier way for it.

[b]trial code2[/b]

[COLOR="#FF0000"]$myWholeRecord[/COLOR]="";

$testResult=mysql_query("select id, name from myTable order by id ") ; 



while($row = mysql_fetch_array($testResult))
{

$myRecord="(". $row['id'].")".$row['name']." <br>";

[COLOR="#FF0000"]$myWholeRecord[/COLOR]=$myWholeRecord.$myRecord;
}


echo [COLOR="#FF0000"]$myWholeRecord[/COLOR];

Change the code inside your while block to

while($row = mysql_fetch_array($testResult))
{
    $myWholeRecord .= "(". $row['id'].")".$row['name']." <br>";
}

.= will append data to an existing variable.

Thank you very much, programhis.