我正在开发一个个人项目,并且如果登录的会话用户尚未关注所显示的用户,我正在尝试创建一个php脚本来显示关注按钮。
这里有我所拥有的:
<?php $query = query("SELECT*FROM following, users WHERE followed_id=" .escape_string($_GET['id'])." AND user_id=".escape_string($_GET['id'])." AND follower_id =".escape_string($_SESSION['user_id']).""); confirm($query); while($row = fetch_array($query)): if(mysqli_num_rows($query)==0){ $followbutton=<<<DELIMITER <form method="post" action=""> <input type="hidden" name="followed" value="{$row['user_id']}"> <input type="hidden" name="follower" value="{$_SESSION['user_id']}"> <input class="btn btn-info" type="submit" name="submit" value="follow"> </form> DELIMITER; echo $followbutton; }elseif($row['follower_id'] == $_SESSION['user_id']){ $unfollowbutton=<<<DELIMITER <form method="post" action="unfollow.php?id={$row['user_id']}"> <input class="btn btn-info" type="submit" value="Unfollow"> </form> DELIMITER; echo $unfollowbutton; } endwhile; ?>
这是查询,escape_string,fetch_array并确认执行的操作:
function redirect($location){ header("Location: $location"); } function query ($sql){ global $connection; return mysqli_query($connection,$sql); } function confirm($result) { global $connection; if(!$result){ die("QUERY FAILED ".mysqli_error($connection)); } } function escape_string($string){ global $connection; return mysqli_real_escape_string($connection,$string); } function fetch_array($result) { return mysqli_fetch_array($result); }
“以下”表只有两列; followed_id和follower_id。当用户单击关注按钮时,它会将登录的user_id传递为follower_id,将要关注的人的user_id传递为followed_id。如果用户A尚未跟随用户B,则不会有任何条目,因此仅当查询未返回任何结果时,才需要显示该按钮。
我正在处理一个个人项目,如果登录的会话用户尚未关注所显示的用户,我正在尝试创建一个php脚本来显示关注按钮。这就是我所得到的:<...>] >
如果我正确理解了您的问题,则您想要显示一个关注
按钮或一个取消关注• 在 PowerShell 中单击 ComboBox 项时无结果
• 如何打印 laravel 查询语句以显示 sql statmnet
• 尽管每个变量都等于准备语句的数量,但变量数量与准备语句中的参数数量不匹配[重复]
• 如何在 Shopify Liquid if 语句中使用多个 'for', 'and'?
• 如何计算 PHPUnit 代码覆盖率的空 foreach 语句中的代码路径?
• 如何修复“mysqli_sql_exception:查询/准备语句中未使用索引 SELECT DISTINCT ...在 C:\xampp\htdocs\...unctions.php:536?