Freedom-n-Democrazy Posted September 25, 2011 Share Posted September 25, 2011 I'm trying to echo multiple rows from a MySQL database with no luck. I've tried this code and many other combinations with it, but can't seem to get a result. $query = "select email,mens,womens from newsletters"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) {foreach ($row as .$email. .$mens. .$womens.) {echo "$email - $mens - $womens<BR>";}} What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/247820-echoing-multiple-rows-from-a-mysql-database/ Share on other sites More sharing options...
trq Posted September 25, 2011 Share Posted September 25, 2011 foreach. Quote Link to comment https://forums.phpfreaks.com/topic/247820-echoing-multiple-rows-from-a-mysql-database/#findComment-1272545 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 25, 2011 Author Share Posted September 25, 2011 I've read that already. Quote Link to comment https://forums.phpfreaks.com/topic/247820-echoing-multiple-rows-from-a-mysql-database/#findComment-1272547 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 25, 2011 Author Share Posted September 25, 2011 I've tried: foreach ($row as $email $mens $womens) foreach ($row as ['$email'] ['$mens'] ['$womens']) foreach ($row as .$email. .$mens. .$womens.) foreach ($row as ".$email." ".$mens." ".$womens.") foreach ($row as $email . $mens . $womens) foreach ($row as $email . $row as $mens . $row as $womens) Quote Link to comment https://forums.phpfreaks.com/topic/247820-echoing-multiple-rows-from-a-mysql-database/#findComment-1272548 Share on other sites More sharing options...
trq Posted September 25, 2011 Share Posted September 25, 2011 Obviously your not reading it properly. The syntax is [ic]foreach ($array as $value) {}[/ci] You need to use list. Quote Link to comment https://forums.phpfreaks.com/topic/247820-echoing-multiple-rows-from-a-mysql-database/#findComment-1272551 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 26, 2011 Author Share Posted September 26, 2011 I have, but the examples used in it suck hard. Quote Link to comment https://forums.phpfreaks.com/topic/247820-echoing-multiple-rows-from-a-mysql-database/#findComment-1272735 Share on other sites More sharing options...
jcbones Posted September 26, 2011 Share Posted September 26, 2011 $query = "select email,mens,womens from newsletters"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { extract($row); echo "$email - $mens - $womens<BR>";} Look at extract() Quote Link to comment https://forums.phpfreaks.com/topic/247820-echoing-multiple-rows-from-a-mysql-database/#findComment-1272737 Share on other sites More sharing options...
Freedom-n-Democrazy Posted September 26, 2011 Author Share Posted September 26, 2011 Will do. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/247820-echoing-multiple-rows-from-a-mysql-database/#findComment-1272741 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.