php - How to put a while loop in a variable? -


OK, actually this code is not high!

  $ toq = mysql_query ("select from users") or die (mysql_error ()); $ From = while ($ row = mysql_fetch_array ($ toq)) {echo "". $ Row ['Mail']. ","; }; Echo per $;    

You want to save all the entries in an array, such as: from $ = array (); While ($ line = mysql_fetch_array ($ toq)) {$ to [] = $ line ['mail']; }

Then, use echo as a comma-separated string:

  echo fonts (',', $ to);   

This is better than alternative, which is to use string combination, but essentially adding an extra comma at the end:

  $ to = ''; While ($ line = mysql_fetch_array ($ toq)) {$ to. = $ Row ['Mail'] ','; }   

To delete that sequential comma, use it:

  $ to = rtrim ($ to, ',');    

Comments