因此,我有一个查询,它从数据库中提取数据并放入一个表中,它还进入一个数组,如下所示:
<table class="list">
<tr>
<th>Rank</th>
<th>Username </th>
<th> Most Steps</th>
<th> Average Steps </th>
<th> Total Steps </th>
</tr>
<?php //get info for scores in the league
if ($result = $link->query("SELECT SUM(DISTINCT step_count.steps) as total, logins.nickname, MAX(step_count.steps) as maxsteps, ROUND(AVG (DISTINCT step_count.steps)) as average, logins.Email as email
FROM step_count
INNER JOIN logins on
step_count.unique_id=logins.unique_id
INNER JOIN leagues ON
leagues.unique_id=logins.unique_id
WHERE step_count.date BETWEEN '$info[start_date]' AND '$info[end_date]'
GROUP BY logins.unique_id
ORDER BY `total` DESC
", MYSQLI_USE_RESULT))
$rank = 1;
//add data to an arry for email use
$leaguedata = array();
while($row = $result->fetch_assoc()){
$leaguedata[] = $row; ?>
<tr>
<td><?php echo $rank++; ?></td>
<td><?php echo $row['nickname']; ?></td>
<td><?php echo $row['maxsteps']; ?></td>
<td><?php echo $row['average']; ?></td>
<td><?php echo $row['total']; ?></td>
</tr>
<?php } $result->close(); ?>
</table>
然后我有一个区域,当联赛结束后,我会在其中发送一封电子邮件,其中包含结果:
<?php //if admin and the date has past, change active to 0
if ($info['role'] == "ADMIN") {
if ($info['end_date'] < date("Y-m-d")) {
$endleague = "UPDATE leagues SET active = 0
WHERE joincode='$joincode'";
mysqli_query($link,$endleague);
echo "<h3><br/>This league has now ended, results will be sent to everyone via email!</h3>";
//send league ending information
$endrank = 1;
$subject = "$league_name has ended!";
$body="Results are in and these were the final scores:".PHP_EOL;
$body.="$endrank++".PHP_EOL;
$headers = "From: localhost";
foreach ($leaguedata as $email){
mail($email['email'], $subject, $body, $headers); }
}
} ?>
我不确定foreach循环在电子邮件正文中是如何工作的,也不确定如何让$endrank++在正文中工作。
1条答案
按热度按时间bvjveswy1#
你的
endrank
行可以是:至于
foreach
语句中,假设要从行中添加一些数据: