gpt4 book ai didi

php - 使用循环将查询变量附加到消息中

转载 作者:行者123 更新时间:2023-11-30 00:21:23 24 4
gpt4 key购买 nike

我有一组电子邮件,用于在 MySQL 中查找它们各自的 CourseID 的配对。

循环应该找到与该电子邮件关联的每个CourseID并将其附加到消息中,然后在完成后将其发送出去。但是,电子邮件会发送它找到的第一个 $row['CourseID'],并且不会显示消息的其余部分或任何其他 $row['CourseID'] > 已找到。

这是我的代码,谁能告诉我我缺少什么?

 <?php
$courseList=array();
$studentList=array();
$subject="Course Surveys";
$con=mysqli_connect("","","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

//populate the course list array
foreach ($_POST['queue'] as $cID)
{
array_push($courseList, $cID);
}
//find all the student emails in each course and put them into an array
for ($i=0; $i<=count($courseList);$i++)
{
$theCourse=$courseList[$i];
$foundemails=mysqli_query($con,"SELECT StudentEmail FROM Students WHERE CourseID='$theCourse'");
while($row=mysqli_fetch_array($foundemails)){
array_push($studentList, $row['StudentEmail']);

}
}
//strip email array of duplicates & restructure array
$studentList = array_unique($studentList);
$studentList = array_values($studentList);

//Send emails
for ($i=0;$i<=count($studentList);$i++)
{

$message = "Hello ".$studentList[$i].", please take the time to complete the following surveys:\n";
$result=mysqli_query($con,"SELECT * FROM Students WHERE StudentEmail='$studentList[$i]'"); /* USE ORDER BY StudentEmail */
while($row=mysqli_fetch_array($result)){
$hashed=md5($studentList[$i].$row['CourseID']);
$message .= $row['CourseID'].":\n http://khaledkloub.com/projects/admin/survey.php?id=".$hashed."\n";
}
mail($studentList[$i], $subject, $message, "From: Course Survey Manager\n");
}

mysqli_close($con);
?>

最佳答案

$message .= $row['CourseID']."\n";

或者

$message = $message . $row['CourseID']."\n";

关于php - 使用循环将查询变量附加到消息中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23208502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com