wright67uk Posted October 3, 2013 Share Posted October 3, 2013 I'm collecting tips on a website, and Im trying to make a 'send as email' feature, where all of the tips from today's date can be sent to users. As Im already displaying todays tips on my website, I would like to put the tips into a variable, ready for mailing. How do I do this? Do I just put $message = (before the while loop?) $query = "SELECT placed, win, id, date, horse, course, odds1, odds2, sp, place, time, tip, description, booky, date_added, time_added FROM toptips WHERE userid = 54 AND `date` ='".$curentDate."' order by date desc"; $result = $mysqli->query($query); while($row = $result->fetch_array()) { $rows[] = $row; } if(count($rows)>0){ foreach($rows as $row) { $date = $row['date']; $date = date("d/m/y", strtotime($date)); $id = $row['id']; $booky = $row['booky']; $sp = $row['sp']; $placed = $row['placed']; // if ($sp === 'yes') {$start = ' SP';} echo '<div style= "width:700px; font-family:verdana;"> <div style="float:left; width:700px; margin-bottom:10px; margin-top: 10px; padding:10px; border: solid 1px grey;"> <h5> ('.$date.") " . $row['time'] . " " . $row['course'] . " - " . $row['horse'] . " " . $row['odds1'] . "/" . $row['odds2'] . $row['sp'] . "-" . $row['place'] . '</h4><img src="' . $row['tip'] . '.png" alt=" '. $row['tip'] .' " height="42" width="42" style="float:right"><br>'. $row['description'] . '... Quote Link to comment https://forums.phpfreaks.com/topic/282671-storing-results-from-a-while-loop-into-a-variable/ Share on other sites More sharing options...
Barand Posted October 3, 2013 Share Posted October 3, 2013 Use concatenation $message = ''; while (whatever) { $message .= someData; } Quote Link to comment https://forums.phpfreaks.com/topic/282671-storing-results-from-a-while-loop-into-a-variable/#findComment-1452381 Share on other sites More sharing options...
cyberRobot Posted October 3, 2013 Share Posted October 3, 2013 Side note: the foreach loop isn't necessary. In the following code, the while loop won't execute if there isn't any data: <?php while($row = $result->fetch_array()) { $date = $row['date']; //... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/282671-storing-results-from-a-while-loop-into-a-variable/#findComment-1452421 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.