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? 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. 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. 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) 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. 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. 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() 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. 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
Archived
This topic is now archived and is closed to further replies.