PHP と MySQL を使用して個人用メッセージング システムを作成しました。システムの一部では、特定のグループに当てはまる人にグループ電子メールを送信できます。
電子メールを送信するためのコードは次のとおりです。
session_start();
include_once('../../dbconnect.php');
$email=$_SESSION['email'];
$to = $_POST ['touser'];
$toemail = $_POST['touseremail'];
$from = $_SESSION['name'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$time = time();
if ($to == 'Level 4'){
$usersquery = "SELECT email FROM users WHERE account = 'Level4'";
$getusers = $conn -> query($usersquery);
while ($row = $getusers->fetch_assoc()){
foreach ($row as $value){
$query ="INSERT INTO messages (to_user, to_email, subject, message, from_user, from_email, daterecord) VALUES ('" . $to . "', '" . $value . "', '" . mysqli_real_escape_string($conn, $subject) . "', '" . mysqli_real_escape_string($conn, $message) . "', '$from', '$email', '$time')";
$send = $conn -> query($query);
}
}
}
これは問題なく機能しますが、問題は、送信ボックスを開くと、個々のメッセージが表示されることです。大きなグループにメッセージが送信されると、送信ボックスが詰まり、非常に迷惑です! 送信ボックスのコードは次のとおりです。
$emailquery = "SELECT * FROM messages WHERE from_email = '$email' AND sent_deleted = 'no' ORDER BY daterecord DESC";
$sentemails = $conn->query($emailquery);
$emailcount = $sentemails ->num_rows;
if ($emailcount == 0){
echo '<div>No messages sent</div>';
}
else{
?>
<table class="udtable">
<tr>
<th class="reqhead">To</th>
<th class="reqhead">Subject</th>
<th class="reqhead"></th>
</tr>
<?
$i=1;
while ($sent = $sentemails->fetch_assoc()){
if ($i%2 != 0){
$rowclass = 'reqodd';
}
else {
$rowclass = 'reqeven';
}
echo ' <tr class = "' . $rowclass . '">
<td class="reqfrom">' . $sent['to_user'] . '</td>
<td class="reqsubj">' . $sent['subject'] . '</td>
<td class="req"><a id="link' . $sent['id'] . '" href="#" class="sentopen">Open</a></td>
<td class="reqmessage"><pre class=sentboxmessage>' . $sent['message'] . '</pre></td>
<td class="reqid">' . $sent['id'] . '</td>
</tr>';
$i++;
}
?>
</table>
<?
}
?>
送信ボックスは次のようになります。
これらのメッセージをすべて 1 行にまとめたいと思います。
何か案は?
ありがとう!