Jump to content

How to use mysql_fetch_array outside while loop


maestrog

Recommended Posts

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;

?>

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.