How do I put a final output from a WHILE loop in a variable and echo it outside of WHILE?
while ($row = mysql_fetch_array($result)) { $names = ''.$row['name'].'<br>';//outputs 10 names } echo $name;//all the 10 names?
Use the ".=" operator:
$names = ''; // initialize to empty string while ($row = mysql_fetch_array($result)) { $names .= $row['name'].'<br>'; //outputs 10 names } echo $names; //all the 10 names
Thanks NogDog. Totally forgot about that dot.