Connecting Tech Pros Worldwide Forums | Help | Site Map

1 or more fetch array

ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#1: Jun 17 '09
I have two separate query on my PHP mailer and I wonder how can it be possible to call the two queries in one fetch array.

Expand|Select|Wrap|Line Numbers
  1. #email process starts here
  2.  
  3.  
  4.         require("class.phpmailer.php");
  5.         $mail = new PHPMailer();
  6.  
  7.         $mail->From     = "xxxx";
  8.         $mail->FromName = "administrator";
  9.         $mail->Subject = "xxxx";
  10.         $mail->Host     = "xx.xx.xx.x"; // SMTP server
  11.         $mail->Mailer   = "smtp";
  12.  
  13.         //$query 
  14.         $query ="SELECT * FROM members";
  15.         $query1 ="SELECT max(fileid) FROM table1";
  16.  
  17.  
  18.         $result=@MYSQL_QUERY($query);
  19.         $result1=@MYSQL_QUERY($query1);
  20.  
  21.         while ($row = mysql_fetch_array ($result, $result1)) {
  22.             // HTML body
  23.             $body  = "Hello <font size=\"4\">" . $row["fname"] . "</font>, <p>";
  24.             $body .= " <font size=\"4\"> A document is now available for your review" . $row["fileid"] ."</font><p>";
  25.             $body .= "http://xx.xx.xx.xxx/data.php?id=\" .$row [fileid] .\"<p>";
  26.             $body .= "Thank You, <br>";
  27.             $body .= "Administrator";
  28.  
  29.  
  30.  
  31.             $mail->Body    = $body;
  32.             $mail->AltBody = $text_body;
  33.             $mail->AddAddress($row["email"], $row["fname"]);
  34.  
  35.             if(!$mail->Send())
  36.                 echo "There has been a mail error sending to " . $row["email"] . "<br>";
  37.  
  38.             // Clear all addresses and attachments for next loop
  39.             $mail->ClearAddresses();
  40.             $mail->ClearAttachments();
  41.         }
  42.  
I know this won't work :) any suggestion how to call two queries?

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#2: Jun 17 '09

re: 1 or more fetch array


you need to combine the two queries, so that you fetch all data at once. I think this can be done using the JOIN syntax (although the SQL people might know better)
prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152
#3: Jun 19 '09

re: 1 or more fetch array


1.if this two tables are different and have no primary and foreign key relation then you could make this query like..

Expand|Select|Wrap|Line Numbers
  1. SELECT members. * , (SELECT max(fileid) FROM table1) AS max_field
  2. FROM members
  3.  
  4.  
:)
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#4: Jun 19 '09

re: 1 or more fetch array


I have 1.2.13 MYSQL Query Browser

And I had error when I execute this query. Any idea why?

Quote:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT max(fileid) FROM table1) AS max_field
FROM members' at
Quote:

Originally Posted by prabirchoudhury View Post

1.if this two tables are different and have no primary and foreign key relation then you could make this query like..

Expand|Select|Wrap|Line Numbers
  1. SELECT members. * , (SELECT max(fileid) FROM table1) AS max_field
  2. FROM members
  3.  
  4.  
:)

Reply