Connecting Tech Pros Worldwide Help | Site Map

1 or more fetch array

  #1  
Old June 17th, 2009, 12:15 AM
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 204
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?
  #2  
Old June 17th, 2009, 05:26 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,487
Provided Answers: 9

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)
  #3  
Old June 19th, 2009, 08:14 AM
prabirchoudhury's Avatar
Familiar Sight
 
Join Date: May 2009
Location: Wellington, New Zealand
Posts: 152

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.  
:)
  #4  
Old June 19th, 2009, 03:58 PM
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 204

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Write Function Pointer Array Immortal Nephi answers 5 June 29th, 2008 10:45 AM
Newbee needs once more again help with passing arrays out of a function Christian Maier answers 4 February 18th, 2007 11:15 AM
A dream of more functional CLP in v8.3 sopranos2@gmail.com answers 38 June 9th, 2006 07:25 PM
Mysterious pointer mixed with array indices bug David Mathog answers 3 March 20th, 2006 04:25 PM