那么描述我想要做的事情有点复杂,让我完全解释一下。首先,我从多个选择中选择了一个或多个选项并将其内嵌到一列中,现在我希望在一列中显示每个选择ID名称。
第一次内爆:
$gallery_category = implode(' ',$_POST['gallery_category']);
然后尝试显示每个唯一ID名称,如此
$gallery_category = $row['gallery_category'];
$output = explode(" ", $gallery_category);
$query = 'SELECT * FROM gallery_category WHERE gallery_category_name2 = "'.$output.'"';
$select_categories_name = mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($select_categories_name)) {
$gallery_category_name = $row['gallery_category_name'];
echo "<td> $gallery_category_name</td>";
}
得到如下错误:注意:数组转换为字符串
答案 0 :(得分:3)
$gallery_category = $row['gallery_category'];
$output = explode(" ", $gallery_category);//this is an array so have to give it in a loop or specify by index
foreach($output as $category)
{
$query = 'SELECT * FROM gallery_category WHERE gallery_category_name2 = "'.$category.'"';
$select_categories_name = mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($select_categories_name)) {
$gallery_category_name = $row['gallery_category_name'];
echo "$gallery_category_name";
}
}
这应该有用,如果没有请注释。