Hilly_2004 Posted May 8, 2006 Share Posted May 8, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/9309-mail-array-loop/ Share on other sites More sharing options...
kenrbnsn Posted May 8, 2006 Share Posted May 8, 2006 Please post the code that didn't work.Ken Quote Link to comment https://forums.phpfreaks.com/topic/9309-mail-array-loop/#findComment-34279 Share on other sites More sharing options...
Hilly_2004 Posted May 8, 2006 Author Share Posted May 8, 2006 This is going to be a coders nightmare so I apologise in advance ;)[code]<?phpinclude("../~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");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9309-mail-array-loop/#findComment-34286 Share on other sites More sharing options...
Hilly_2004 Posted May 9, 2006 Author Share Posted May 9, 2006 Nobody?Is there an example of a piece of code I can edit to suit my requirements? Quote Link to comment https://forums.phpfreaks.com/topic/9309-mail-array-loop/#findComment-34491 Share on other sites More sharing options...
Hilly_2004 Posted May 9, 2006 Author Share Posted May 9, 2006 *Bump* Quote Link to comment https://forums.phpfreaks.com/topic/9309-mail-array-loop/#findComment-34660 Share on other sites More sharing options...
JRS Posted May 9, 2006 Share Posted May 9, 2006 [!--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) [snapback]372654[/snapback][/div][div class=\'quotemain\'][!--quotec--]*Bump*[/quote]HillyTry the tutorial on this site all about php_mailer - take my advise and use phpmailer for allemailing stuff.[a href=\"http://www.phpfreaks.com/tutorials/130/0.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorials/130/0.php[/a]good luckJRS Quote Link to comment https://forums.phpfreaks.com/topic/9309-mail-array-loop/#findComment-34684 Share on other sites More sharing options...
Hilly_2004 Posted May 10, 2006 Author Share Posted May 10, 2006 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....[code]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>";}[/code]etc...etc... but 10 times!!!! Quote Link to comment https://forums.phpfreaks.com/topic/9309-mail-array-loop/#findComment-34813 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.