Jump to content


Photo

Mail Array Loop


  • Please log in to reply
6 replies to this topic

#1 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 08 May 2006 - 01:47 PM

Hi guys,

Wondering if you could help me. Im wanting to create a mailer which emails a user a list of details from the database in one email.

The user selects which people they wish to recieve more details of and enters their email address, and finally posts their ID's as part of an array e.g.

$studentIDs = $_REQUEST['studentIDs'];
$emailAddress = $_REQUEST['emailAddress'];


($studentIDs = "1-14-19-13...etc")

I then explode the array to retrieve the certain ID's e.g.

$idArray = explode("-", $studentIDs);

The next part is where I get stuck, how can I then select these users from the database and the email the results to the email address the user provided ($emailAddress).

I tried using a loop however this caused only the final entry that was exploded to be mailed to the user instead of a list of all of them. Hope this makes sense.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 May 2006 - 01:58 PM

Please post the code that didn't work.

Ken

#3 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 08 May 2006 - 02:19 PM

This is going to be a coders nightmare so I apologise in advance ;)

<?php

include("../~lib/lib.php");
//check this is flash calling the script
//ignore it for now
//$error = authorise($_REQUEST['authorised']);
if (isset($_REQUEST['studentIDs'])) {
$error = 0;

//get student id's passed by flash
$studentIDs = $_REQUEST['studentIDs'];

//get email address to send to
$emailAddress = $_REQUEST['emailAddress'];

//create array of student id's
$idArray = explode("-",  $studentIDs);

foreach ($idArray AS $key => $value){
    
  //  echo "$value <br>";
    

//print student id's on screen for stephen to see
//print_r ($idArray);
//echo("<br />");

//print email address on screen for stephen to see
//echo ($emailAddress."<br />");



$message = '';

//-----GET ANY REPLIES TO THE TOPIC-----
$Query3 = "SELECT * FROM students_test WHERE studentID = '$value'";
$Result3 = mysql_query($Query3);
$num = mysql_num_rows($Result3);
if ($Result3) {
      while($row = mysql_fetch_array($Result3)) {
      
      $firstname = array($row['firstName']);
      foreach ($firstname as $cheese)
      {
      
      }
      
      $lastname = array($row['lastName']);
      foreach ($lastname as $ham)
      {
      
      }
      
      $email = array($row['email']);
      foreach ($email as $pickel)
      {
      
      }
     // echo "".$row['firstName']."";
      //echo "".$row['lastName']."";
        
//$message = $pickel;
      }
      $subject = "Hello Gareth...";

mail("$emailAddress", "$subject", 
    "<html>
<body>
<table width=\"100%\"  border=\"0\">
  <tr>
    <td bgcolor=\"#0000FF\"><div align=\"center\">$pickel</div></td>
  </tr>
</table>
</body>
</html>", 
    "To: The Receiver <$emailAddress>\n" . 
    "From: The Sender <noreply@lineupthedots.com>\n" . 
    "MIME-Version: 1.0\n" . 
    "Content-type: text/html; charset=iso-8859-1"); 

      
      
      }
      }
      
      }
//-----SHOW ALL REPLIES
//$replies = 0;
//while ($replies < $num)
//{

//$lname = mysql_result($Result3,$replies,"lastName");
//$fname = mysql_result($Result3,$replies,"firstName");






//$replies++;
//} //-----END SHOW ALL REPLIES




//get those student's info from db and make a nice html email to send to user with all of selected student's info in :)
//don't print anything else to the screen
//if anything goes wrong, tell flash by setting $error = 1
//$error = 1;

//tell flash it's done
//echo("&error=".$error."&loaded=1");

?>



#4 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 09 May 2006 - 02:21 AM

Nobody?

Is there an example of a piece of code I can edit to suit my requirements?

#5 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 09 May 2006 - 04:52 PM

*Bump*

#6 JRS

JRS
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 09 May 2006 - 06:22 PM

[!--quoteo(post=372654:date=May 9 2006, 12:52 PM:name=Hilly_2004)--][div class=\'quotetop\']QUOTE(Hilly_2004 @ May 9 2006, 12:52 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
*Bump*
[/quote]
Hilly
Try the tutorial on this site all about php_mailer - take my advise and use phpmailer for all
emailing stuff.
[a href=\"http://www.phpfreaks.com/tutorials/130/0.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorials/130/0.php[/a]

good luck
JRS

#7 Hilly_2004

Hilly_2004
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 10 May 2006 - 03:25 AM

Cheers for that JRS, Il try and employ some of the code into the workings of mine...

Ive managed to kind of do this loop thing I was on about however I know for a fact that it could and SHOULD be done much easier, instead Ive had use 10 sql queries to get 10 bits of information out of the database (10 being the maximum number of people a user can select), I know it should be done using an array but I dont know how....

if (isset($_REQUEST['studentIDs'])) {
$error = 0;

//get student id's passed by flash
$studentIDs = $_REQUEST['studentIDs'];

//get email address to send to
$emailAddress = $_REQUEST['emailAddress'];

//create array of student id's
$idArray = explode("-",  $studentIDs);

$test = array($idArray);
foreach($test AS $key => $value)

//---------------------------------------------------------------------------
$Query3 = "SELECT * FROM students_test WHERE studentID = '$value[0]'";
$Result3 = mysql_query($Query3);
$num = mysql_num_rows($Result3);
if ($Result3) {
while($row = mysql_fetch_array($Result3)) {
$firstname = $row['firstName'];
$blurb = $row['blurb'];
$lastname = $row['lastName'];

$course = $row['course'];
if ($course == 'i'){$course = "Interactive Multimedia";} 
else if ($course == "w"){$course = "Web Design";} 
else if ($course == "g"){$course = "Games Design";}

$web = $row['web'];
        }
    }
if($firstname == ''){}
else {
$user = "<strong>$firstname $lastname</strong><br>
    $course<br>
    <a href=\"http://$web\">$web</a><p>
    $blurb</p>
    <hr>";
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
$Query3 = "SELECT * FROM students_test WHERE studentID = '$value[1]'";
$Result3 = mysql_query($Query3);
$num = mysql_num_rows($Result3);
if ($Result3) {
while($row = mysql_fetch_array($Result3)) {
$firstname1 = $row['firstName'];
$blurb1 = $row['blurb'];
$lastname1 = $row['lastName'];

$course1 = $row['course'];
if ($course1 == 'i'){$course1 = "Interactive Multimedia";} 
else if ($course1 == "w"){$course1 = "Web Design";} 
else if ($course1 == "g"){$course1 = "Games Design";}

$web1 = $row['web'];
        }
    }
if($firstname1 == ''){}
else {
$user1 = "<strong>$firstname1 $lastname1</strong><br>
    $course1<br>
    <a href=\"http://$web1\">$web1</a><p>
    $blurb1</p>
    <hr>";
}

//---------------------------------------------------------------------------
$Query3 = "SELECT * FROM students_test WHERE studentID = '$value[2]'";
$Result3 = mysql_query($Query3);
$num = mysql_num_rows($Result3);
if ($Result3) {
while($row = mysql_fetch_array($Result3)) {
$firstname2 = $row['firstName'];
$blurb2 = $row['blurb'];
$lastname2 = $row['lastName'];

$course2 = $row['course'];
if ($course2 == 'i'){$course2 = "Interactive Multimedia";} 
else if ($course2 == "w"){$course2 = "Web Design";} 
else if ($course2 == "g"){$course2 = "Games Design";}

$web2 = $row['web'];
        }
    }
if($firstname2 == ''){}
else {
$user2 = "<strong>$firstname2 $lastname2</strong><br>
    $course2<br>
    <a href=\"http://$web2\">$web2</a><p>
    $blurb2</p>
    <hr>";
}

etc...etc... but 10 times!!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users