我正在努力解决我的问题。我已经创建了代码并在 PHP 中运行良好,但我现在想将其演变为最终用户的更好的工作解决方案。
我有一组链接来确认或拒绝某项操作。一旦用户单击“确认”/“拒绝”,我希望这可以使用 AJAX 将值保存到 db,然后li
使用 jQuery 制作动画。
目前我使用了 php,它重定向到 URL。任何帮助/指导将不胜感激。
这是我的代码:
链接
<?php
$friend_unconfirmed_from_them = mysql_query('
SELECT * from wallfriends
where mem_id_to ='.$USER->id.' AND confirm = 0
'); //unconfirmed friends to logged in user ($USER->id)
while ($friendrequest = mysql_fetch_array($friend_unconfirmed_from_them, MYSQL_ASSOC)) {
$senders_name = mysql_query('
SELECT firstname, lastname from mdl_user
where id = '.$friendrequest['sender'].'
'); //get unconfirmed friends name
while ($sender = mysql_fetch_array($senders_name, MYSQL_ASSOC)) {
?>
<li><?php echo $sender['firstname'].' '.$sender['lastname'];
}?>
<a href="confirmfriend.php?userid=<?php echo $friendrequest['sender']; ?>">Confirm Link</a>
<a href="removefriend.php?userid=<?php echo $friendrequest['sender']; ?>">Deny Link</a></li>
//echo each friend in li with confirm deny links
<?php } ?>
</ul>
确认朋友.php
$userid = optional_param('userid', 0, PARAM_INT);
$connection = mysql_connect("localhost", "root", "on10n") or die ("Unable to connect!");
mysql_select_db("fe") or die ("Unable to select database!");
$query = "UPDATE wallfriends SET confirm = 1 WHERE mem_id_to = '$USER->id' AND mem_id_from = '$userid'";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
if (!$result){
echo "There were errors :<br>". mysql_error();
}
else{
redirect($siteUrl.'/profile.php?userid='.$userid.'');
die;
}
拒绝朋友.php
$userid = optional_param('userid', 0, PARAM_INT);
$connection = mysql_connect("localhost", "root", "on10n") or die ("Unable to connect!");
mysql_select_db("fe") or die ("Unable to select database!");
$query = "DELETE FROM wallfriends
WHERE (mem_id_from = '$USER->id' OR mem_id_from = '$userid')
AND (mem_id_to = '$USER->id' OR mem_id_to = '$userid')
";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
if (!$result){
echo "There were errors :<br>". mysql_error();
}
else{
redirect($siteUrl.'/profile.php?userid='.$userid.'');
die;
}