需要一些幫助來完成我的代碼它所做的是在我的數據庫表中搜索指向parent_sections = 2的所有部分,然後將結果打印在選擇標記中我想要一些幫助用於檢查parent_sections = 2是否具有子項的sql查詢,如果是,則使用optgroup樣式打印它們,請檢查下面的圖像以解釋我需要的內容。sql查詢結果來自父母
PHP & SQL代碼:
<?php
include('../application_top.php');
function get_title_sections($id){
$sections_query = tep_db_query("select title_sections_detail from sections_detail where id_sections = '" . (int)$id . "' and id_lang='0' order by title_sections_detail");
$result='';
while ($sections = tep_db_fetch_array($sections_query)) {
$result=$sections['title_sections_detail'];
}
return $result;
}
?>
<form>
<select name="sections">
<option selected="selected" value="">Please choose an option</option>
<?php
$sections_sql=tep_db_query("select p.id_sections, d.title_sections_detail as title from sections p, sections_detail d where p.id_sections=d.id_sections and d.id_lang='0' and p.status_sections='1' and p.parent_sections='2' order by d.title_sections_detail asc");
while ($sections = tep_db_fetch_array($sections_sql)) {
$id_sec=$sections['id_sections'];
$title_sec=get_title_sections($id_sec);
?>
<option value="<?php echo $id_sec ?>" ><?php echo $title_sec ?></option>
<?php }?>
</select>
</form>
SQL桌子部分:
SQL表sections_detail:
結果:
結果,我需要:
您需要使用'
添加父標記 – wesside