当我使用 PHP 进行循环时,我遇到了一些问题。这里的代码:
$subsel = mysql_query ("SELECT * FROM ar_subkategori, ar_subkategori_bhs WHERE ar_subkategori.id_subkategori = ar_subkategori_bhs.id_subkategori AND id_bahasa = 1 AND status = 'y'");
while ($getsubsel = mysql_fetch_array($subsel)){
if($getsubsel['id_subkategori_induk'] == 0){
for($d = 0; $d < $cnt; $d++){
$fetchit = mysql_query("SELECT * FROM ar_subkategori WHERE id_subkategori = $detail_sub[$d]");
$datafetch = mysql_fetch_array($fetchit);
$id_values = $datafetch['id_subkategori'];
if ($id_values == $getsubsel['id_subkategori']){
echo "<input type='checkbox' name='checkbox[]' id='checkbox' value='$getsubsel[id_subkategori]' checked> <span style='font-size:10px; color:#FFA412;'>[ID: $getsubsel[id_subkategori]]</span> $getsubsel[nama_subkategori]</br>";
}
}
if ($id_values != $getsubsel['id_subkategori']){
echo "<input type='checkbox' name='checkbox[]' id='checkbox' value='$getsubsel[id_subkategori]'> <span style='font-size:10px; color:#FFA412;'>[ID: $getsubsel[id_subkategori]]</span> $getsubsel[nama_subkategori]</br>";
}
} else {
for($d = 0; $d < $cnt; $d++){
$fetchit = mysql_query("SELECT * FROM ar_subkategori WHERE id_subkategori = $detail_sub[$d]");
$datafetch = mysql_fetch_array($fetchit);
$id_values = $datafetch['id_subkategori'];
if ($id_values == $getsubsel['id_subkategori']){
echo "<input type='checkbox' name='checkbox[]' id='checkbox' value='$getsubsel[id_subkategori]' checked> <span style='font-size:10px; color:#FFA412;'>[ID: $getsubsel[id_subkategori]]</span> $getsubsel[nama_subkategori] <span style='color:#FFA412; font-style:italic; font-size:12px;'>*Ini adalah sub dari ID: $getsubsel[id_subkategori_induk]</span></br>";
}
}
if ($id_values != $getsubsel['id_subkategori']){
echo "<input type='checkbox' name='checkbox[]' id='checkbox' value='$getsubsel[id_subkategori]'> <span style='font-size:10px; color:#FFA412;'>[ID: $getsubsel[id_subkategori]]</span> $getsubsel[nama_subkategori] <span style='color:#FFA412; font-style:italic; font-size:12px;'>*Ini adalah sub dari ID: $getsubsel[id_subkategori_induk]</span></br>";
}
}
}
这里是该代码的捕获。
我的问题是,如何消除多重/双重数据显示?非常感谢你帮助我。