我一直致力於製作類似於Facebook的社交網絡,以便在我的家庭服務器上使用。但是,我遇到了在用戶配置文件的通知選項卡中顯示好友請求的問題。顯示好友請求
<?php
//Check for notifications script
$Request = "Requests";
$Pending = "Pending";
$nCheck = mysqli_query($Connect,"SELECT * FROM friends WHERE rTo = '$Uname' AND Status = '$Pending'");
$nNum = mysqli_num_rows($nCheck);
if($nNum != 0){
if($nNum === 1){
$Request = "Request";
}
else
{
$Request = "Requests";
}
echo"<p style=\"font-family: Tahoma; margin-left: 20px;\">You Have <b>$nNum</b> Friend $Request</p><hr />";
while($row = mysqli_fetch_assoc($nCheck)){
$dbFrom = $row['rFrom'];
$dbId = $row['id'];
$dbStatus = $row['Status'];
for($i = 0; $i < 1; $i++){
echo"<p style=\"font-family: Tahoma; margin-left: 20px;\">$dbFrom wants to be your friend <form action=\"\" method=\"POST\"><input type=\"submit\" name=\"A\" value=\"Accept\"></form> <form action=\"\" method=\"POST\"><input type=\"submit\" name=\"D\" value=\"Decline\"></form></p>";
}
}
}
else
{
echo "<p style=\"font-family: Tahoma; margin-left: 20px;\">You Have <b>0</b> Friend $Request</p>";
}
?>
然後這是形式的接受/拒絕:
<?php
//Accept/Decline Friend Request Script
$Accepted = @$_POST['A'];
$Declined = @$_POST['D'];
$A = "Accepted";
$D = "Declined";
if($Accepted){
$addFriend = mysqli_query($Connect,"UPDATE friends SET Status = '$A' WHERE rTo = '$Uname' AND rFrom = '$dbFrom'");
header("Location: Notification.php");
}
else if($Declined){
$addFriend = mysqli_query($Connect,"UPDATE friends SET Status = '$D' WHERE rTo = '$Uname' AND rFrom = '$dbFrom'");
header("Location: Notification.php");
}
?>
的問題是,如果超過一個通知,最近一次通知將是被接受或拒絕的一個。請大家幫忙,非常感謝。
+1用於提示PDO :) – luschn