roldahayes Posted November 23, 2012 Share Posted November 23, 2012 Hi, This code returns 2 table fields. "code" then "name" all works well until 2 or more rows are retuned and then it displays in one long line.... How can I get it to display each line separately? $message .= $row['code'] ." - ". $row["name"]; Quote Link to comment https://forums.phpfreaks.com/topic/271067-how-to-display-this-data-in-rows/ Share on other sites More sharing options...
White_Lily Posted November 23, 2012 Share Posted November 23, 2012 Post the code for the whole loop and then we can help you properly. Quote Link to comment https://forums.phpfreaks.com/topic/271067-how-to-display-this-data-in-rows/#findComment-1394590 Share on other sites More sharing options...
roldahayes Posted November 23, 2012 Author Share Posted November 23, 2012 if(mysql_num_rows($result) >= 1) { $email = 'mymail@gmail.com'; $subject = "LOW STOCK WARNING!"; $message = "One or more products are running low:\r\n\r\n"; while($row = mysql_fetch_assoc($result)) { $message .= $row['code'] ." - ". $row["name"]; } if(mail($email, $subject, $message)) { //mail successfully sent } else { //mail unsuccessful } } Quote Link to comment https://forums.phpfreaks.com/topic/271067-how-to-display-this-data-in-rows/#findComment-1394591 Share on other sites More sharing options...
Christian F. Posted November 23, 2012 Share Posted November 23, 2012 Add a newline ("\n") to the end of the string, inside the loop. Quote Link to comment https://forums.phpfreaks.com/topic/271067-how-to-display-this-data-in-rows/#findComment-1394592 Share on other sites More sharing options...
roldahayes Posted November 23, 2012 Author Share Posted November 23, 2012 (edited) Thanks I see where I was going wrong, I've fixed it with: $message .= $row['code'] ." - ". $row["name"]."\n"; Edited November 23, 2012 by roldahayes Quote Link to comment https://forums.phpfreaks.com/topic/271067-how-to-display-this-data-in-rows/#findComment-1394647 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.