是否可以从一列的 ID 组合中 select 并显示每个 ID 名称?
is it possible to select from a combination of IDs from one column n display each IDs name?
好吧,描述我正在尝试做的事情有点复杂,让我完整地解释一下。首先,我从多项选择中选择了一个或多个选项并将其内爆到一列中,现在我想在一列中显示每个选择 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>";
}
出现如下错误:注意:数组到字符串的转换
$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";
}
}
这应该可以,如果不行请评论。
好吧,描述我正在尝试做的事情有点复杂,让我完整地解释一下。首先,我从多项选择中选择了一个或多个选项并将其内爆到一列中,现在我想在一列中显示每个选择 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>";
}
出现如下错误:注意:数组到字符串的转换
$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";
}
}
这应该可以,如果不行请评论。