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;

?>

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

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?

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.