我在数据库中有一个名为snapshot的列
快照
US,96,97,89
89
US,56,58
SS,TEST
当我使用分隔符(逗号)爆炸上表时,我将输出为
美国//重复元素
96
97
89 //重复元素
89
美国//重复元素
56
58
SS
TEST
我把代码写成
$sqll = "select distinct unique_id,MAX(snapshot) from unique Group By snapshot order by snapshot ASC"; $q = mysql_query($sqll) or die(mysql_error()); ?>
<option value="">Select</option>
<?php
while($r = mysql_fetch_array($q))
{?>
<?php
$e = explode(",", $r[0]);
foreach($e as $r)
{?>
<option value="<?php echo $r; ?>"><?php echo $r; ?>
</option>
<?php }?>
<?php>
任何最佳查询请更新!!!!!!!!!!!!!!!!!! 我无法得到
答案 0 :(得分:0)
尝试:
$sqll = "select distinct unique_id,MAX(snapshot) from unique Group By snapshot order by snapshot ASC"; $q = mysql_query($sqll) or die(mysql_error()); ?>
<option value="">Select</option>
<?php
while($r = mysql_fetch_array($q)) {
$e = explode(",", $r[0]);
$e = array_unique($e); //removes redundant array values
foreach($e as $r=>$val)
{
echo "<option value='".$val."'>".$val."</option>";
}
}
?>