dlebowski Posted December 8, 2009 Share Posted December 8, 2009 I want to email my customers a list of stuff they bought. I figure out that I have to use the implode function to get that to work. My question is how do i get it so that it will put the data in a table format so each entry is on it's own line? include("dbinfo.inc.php"); mysql_connect("localhost",$uname,$pword) or die("cannot connect"); mysql_select_db("$database")or die("cannot select DB"); $query33="SELECT LotNumber, LotTitle, SellingPrice, LotQuantity, Buyer FROM lots WHERE Date='2009-12-06' and Buyer='1821'"; $result33=mysql_query($query33); $num33=mysql_numrows($result33); mysql_close(); while ($row33 = mysql_fetch_row($result33)) { print $comma_separated = implode(" ", $row33 ); } Quote Link to comment https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/ Share on other sites More sharing options...
mikesta707 Posted December 8, 2009 Share Posted December 8, 2009 if its a plain text email, you can just use the newline character (\n) to put each entry on its own line $comma_separated = implode("\n", $row33 ); if you want an actual HTML table, it will be a little more complicated, and probably require something more complicated than a simple impode() call Quote Link to comment https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/#findComment-973790 Share on other sites More sharing options...
dlebowski Posted December 8, 2009 Author Share Posted December 8, 2009 Right, that is why I was asking what I need to do from here. I wasn't sure someone else had ran into this and had already came up with a solution. Thanks for the quick reply. Quote Link to comment https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/#findComment-973792 Share on other sites More sharing options...
mikesta707 Posted December 8, 2009 Share Posted December 8, 2009 Here is a basic example echo "<table>"; while ($row33 = mysql_fetch_row($result33)) { echo "<tr><td>"; print implode(" ", $row33 ); echo "</td></tr>"; } echo "</table>"; I don't know what $row33 is though (IE what values it has, how its formatted), or how you want your table formatted, but you should get the idea. If you wanted each "imploded" entry in $row33 to be a column, something like { echo "<tr><td>"; print implode("</td><td>", $row33 ); echo "</td></tr>"; } as the while loop should do the trick Quote Link to comment https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/#findComment-973795 Share on other sites More sharing options...
dlebowski Posted December 8, 2009 Author Share Posted December 8, 2009 That is great. I am closer now. Thank you. Now how do I get the "message" portion of the mail() function to allow me to insert that? It does like a lot of php in the message body. Quote Link to comment https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/#findComment-973798 Share on other sites More sharing options...
mikesta707 Posted December 8, 2009 Share Posted December 8, 2009 instead of echoing the table, you would store it into a variable, and just put that into the message body. You have to make sure you set the appropriate headers so your email is read as an HTML email Quote Link to comment https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/#findComment-973800 Share on other sites More sharing options...
dlebowski Posted December 9, 2009 Author Share Posted December 9, 2009 I have the mail() fuction working fine without this code. My dilemma is that I don't know how to put that while loop into a variable. If you can help me with that, then this thing will be solved. Thanks so much for your help. Ryan Quote Link to comment https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/#findComment-973848 Share on other sites More sharing options...
dlebowski Posted December 9, 2009 Author Share Posted December 9, 2009 Thanks again for your help. Here is how I actually got it to work the way I wanted it to. I just inserted the $query variable into the "message" portion of my email function. Worked great! $query = ''; while ($row33 = mysql_fetch_array($result33)) { $query .= ' <tr><td style="text-align: center;"> ' . $row33['LotNumber'] . ' </td><td> ' . $row33['LotTitle'] . ' </td><td style="text-align: center;"> ' . $row33['SellingPrice'] . ' </td><td style="text-align: center;"> ' . $row33['LotQuantity'] . ' </td></tr> '; } print $query; Quote Link to comment https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/#findComment-973981 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.