Php 函数来分隔列
这是我的友谊桌: 如何查询删除自己的id?我是user_id=1 如何打印我的朋友?(2、3和5)Php 函数来分隔列,php,function,Php,Function,这是我的友谊桌: 如何查询删除自己的id?我是user_id=1 如何打印我的朋友?(2、3和5) 现在有点阻塞:(简化您的逻辑。您只需检查if($como!=$user\u id) 试试像这样的东西- $showFriends = $mysqli->query("SELECT * FROM relationship WHERE (user1_id = '$user_id' OR user2_id = '$user_id') AND status = 1") or die(mysqli_
现在有点阻塞:(简化您的逻辑。您只需检查
if($como!=$user\u id)
试试像这样的东西-
$showFriends = $mysqli->query("SELECT * FROM relationship WHERE (user1_id = '$user_id' OR user2_id = '$user_id') AND status = 1") or die(mysqli_error($mysqli));
if($showFriends->num_rows > 0) {
while($f = $showFriends->fetch_assoc()) {
foreach($f as $como) {
if($como != $user_id){
echo $como;
}
}
}
else {
echo "You have no friends!";
}
我们假设您已经正确地清理了
$user\u id
以防止sql注入。如果没有,请确保访问其中user1\u id!=MY\u id!和user2\u id!=MY\u id
?您尝试过什么吗?您是想将该csv作为mysql结果返回,还是通过php格式返回?@Darren可能是正确的想法,但这一切都很明确y不起作用。Darren这不可能,因为我可以在任何一列中。也许我应该考虑更改表。创建一个新表…@Darren,使用pseduo代码是完全有效的,但这应该是一个合理的例子。谢谢你的帮助!:)我这样做只是为了清理数据:$id=strip_标记(htmlentities(htmlspecialchars($id));不确定什么是SQL注入。。
$showFriends = $mysqli->query("SELECT * FROM relationship WHERE (user1_id = '$user_id' OR user2_id = '$user_id') AND status = 1") or die(mysqli_error($mysqli));
if($showFriends->num_rows > 0) {
while($f = $showFriends->fetch_assoc()) {
foreach($f as $como) {
if($como != $user_id){
echo $como;
}
}
}
else {
echo "You have no friends!";
}