maestrog Posted July 14, 2008 Share Posted July 14, 2008 I would like some help with something I always wanted to know. I am making a newsletter and cannot mail() outside of while loop...it mails the last row only. If I mail inside the loop, it mails for as many times as there are rows. Global is for variables and GLOBALS seems to be shunned. Any ideas would be appreciated. Also, how to identify a row by attaching its id#. <?php $edit = "SELECT top_id, title, title_size, text FROM $da_table"; $editor = mysql_query($edit, $link); while ($edi = mysql_fetch_array($editor , MYSQL_ASSOC)) { $id = $edi['top_id']; $tsize = $edi['title_size']; $title = $edi['title']; $text = $edi['text']; $body_new = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n" ."<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" ."<head>\n" ."<title>my html</title>\n" ."</head>\n" ."<body topmargin=0><font face=$font size=$size color=$color><br />\n" ."<p><font size=$tsize>$title</font></p>" ."<p><font size=$font>$text</font></p>" ."<p><hr></p>" ."</body>\n" ."</html>\n"; } echo $body_new; ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted July 14, 2008 Share Posted July 14, 2008 I won't even ask what you're trying to do... but the issue is that you're not appending to your strings. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 14, 2008 Share Posted July 14, 2008 i'm confused as to what the result you are looking for is... is this it? <?php $body_new = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n" ."<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" ."<head>\n" ."<title>my html</title>\n" ."</head>\n" ."<body topmargin=0><font face=$font size=$size color=$color><br />\n"; $edit = "SELECT top_id, title, title_size, text FROM $da_table"; $editor = mysql_query($edit, $link); while ($edi = mysql_fetch_array($editor , MYSQL_ASSOC)) { $id = $edi['top_id']; $tsize = $edi['title_size']; $title = $edi['title']; $text = $edi['text']; $body_new .= "<p><font size=$tsize>$title</font></p>" ."<p><font size=$font>$text</font></p>" ."<p><hr></p>"; } $body_new .= "</body>\n" ."</html>\n"; echo $body_new; ?> Quote Link to comment Share on other sites More sharing options...
maestrog Posted July 14, 2008 Author Share Posted July 14, 2008 Simply put, I can echo all mysql row data inside the loop, but if I do a mail() inside the loop I mail once for every row. If I do a mail outside the loop, only my last row shows up. See, every sql row is a topic and text with that topic, but I can only print or echo it and not mail(). Any clearer? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 14, 2008 Share Posted July 14, 2008 inside the loop you BUILD $body_new by appending text to it. then, outside the loop, you use mail() to send the text Quote Link to comment 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.