1

当我使用 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>";
            }
        }
    }

这里是该代码捕获。

我的问题是,如何消除多重/双重数据显示?非常感谢你帮助我。

4

1 回答 1

0

你需要把它放在''这里value='$getsubsel[id_subkategori]' - value='$getsubsel[\'id_subkategori\']'让它工作。

不要坚持mysql_*学习PDOmysqli_*作为旁注。

于 2013-05-23T03:19:44.380 回答