LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2006, 01:36 PM   #1
madscotsman
LQ Newbie
 
Registered: Nov 2006
Posts: 1

Rep: Reputation: 0
PHP Help Needed Afore Ah Go Mad!!!


Hi Folks

Greetings fi Scotland!

First post here (and Im pretty new to the auld PHP / MySQL so please - assume I know not a lot ;-)

OK ... so, here is my problemo - ... I have;

1 x table with 2 fields (id, email) .. with 2 email addys in for test purposes

1 x table with details to be issued and sent to ALL email addresses in the above table ...

Now...I have this code below (which basically, after I've updated the details on gig page, will send a notice to all email subscribers telling them the details of hte gig ... this is still in test so dont worry about hte content itself ...

My problem - the stoopid thing sends the email to the last ID on the member table!!! WHY WHY oh bloody why!!

Here is the code in question:



$result = mysql_query("select * FROM member order by id");

while($r=mysql_fetch_array($result))
{

$email=$r["email"];

$to = $email;
$subject = "Gig Information";
$body = "Venue: $venue \nDate: $date \nDoors: $doors \nSupport: $support \nPrice: $price";
}

if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}

include 'library/closedb.php';
?>


Now, this DOES work to a point i.e. it does send out the gig variables ($venue etc) which I pulled in .. all cool, the problemo is my loop methinks..but I am a real amatuer at this and basically have read tutorials and self taught myself ... so, possibly missed some fundamentals.

ANY HELP ANYONE GIVES IS MUCHOS APPRECIATEDO!

Ta very much.

(getting madder by the minute) Scotsm...
 
Old 11-11-2006, 02:18 PM   #2
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
Pull the mail statement into the while loop... what you now have is that the while loop will process all ids, and end up at the last one. Only then does your code send a (single) mail.

This would be better:
Code:
while($r=mysql_fetch_array($result))
{
  $email=$r["email"];

  $to = $email;
  $subject = "Gig Information";
  $body = "Venue: $venue \nDate: $date \nDoors: $doors \nSupport: $support \nPrice: $price";
  if (mail($to, $subject, $body)) {
    echo("<p>Message successfully sent!</p>");
  } else {
    echo("<p>Message delivery failed...</p>");
  }
}
O and please, we're all grown-ups here, so you can just use normal english. We will understand.

Eric
 
  


Reply

Tags
loop



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Needed Help in PHP essoft478 Programming 1 05-21-2005 12:31 PM
PHP help needed. BigFred Programming 3 10-09-2003 01:07 AM
:mad: Installation prob :mad: soodvarun Red Hat 0 09-12-2003 01:44 AM
OS X PHP mysql help needed iJasonT Linux - Software 1 05-04-2003 09:32 PM
php is making me mad... BrianG Linux - General 6 06-25-2002 04:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration