Jump to content

Using mail() function with implode


dlebowski

Recommended Posts

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 );
                                }

Link to comment
https://forums.phpfreaks.com/topic/184466-using-mail-function-with-implode/
Share on other sites

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

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

 

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

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.