【发布时间】:2016-04-03 16:45:11
【问题描述】:
我已将 ID 存储为 STRING 个对帖子进行评分的用户。示例:
$ids="5,8,4,9,7,8,87";
然后我将字符串转换为数组:
$kaboom = explode(',',$ids);
现在我想查询另一个表并选择在数组$kaboom 中找到id 的所有字段。我试过了,但出现以下错误:
注意:第 22 行 C:\xampp\htdocs\cebs\include\post_reacts.php 中的数组到字符串转换
这是我的代码:
<?php
//include connection file
include 'dbc.php';
if(isset($_POST['post_id'])){
$post_id = $_POST['post_id'];
//SELECT ALL IDS OF THOSE WHO RATED THE POST
$query = mysqli_query($dbc_conn,"SELECT highlight_voters FROM $public_feed_table WHERE id='$post_id' LIMIT 1");
if($query==true){
while($row=mysqli_fetch_assoc($query)){
$ids = $row['highlight_voters'];
$kaboom = explode(",",$ids);
//select IDS which is/are in array and and get details about the ID
$check_ids_which_in_array = mysqli_query($dbc_conn,"SELECT * FROM $table_name WHERE id='$kaboom' ");
}
if($check_ids_which_in_array==true){
while($b=mysqli_fetch_assoc($check_ids_which_in_array)){
$person_who_rated =$b['id'];
//do something here after...
}
}
}
}
?>
【问题讨论】:
-
@Mihai:我认为应该是
WHERE ids IN ($ids)- $kaboom 是爆炸版本,无论如何都会被转换回字符串Array。 -
OP,请注意
$ids没有被污染 - 如果它来自用户,那么您将不得不将其爆炸、清理并再次内爆。