我只是一個業餘的腳本編碼。我需要幫助從有人在這裏.. 我有麻煩在這裏,我試圖表明2條件從我的代碼合併,看看這裏,請...從2查詢合併2條件數組1
<ul class="nav navbar-nav">
<?php
$main=mysql_query("SELECT * FROM mainmenu WHERE aktif='Y'");
while($r=mysql_fetch_array($main)){
$t=$r[''];
$tm="<a href='$r[link]' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-expanded='false'>$r[nama_menu]<span class='caret'></span></a>";
$th="<a href='$r[link]'>$r[nama_menu]</a>";
if ($t!= ""){
$tombol=$th;
}else{
$tombol=$tm;
}
echo "<li class='dropdown'>$tombol
<ul class='dropdown-menu' role='menu'>";
\t $sub=mysql_query("SELECT * FROM submenu, mainmenu
WHERE submenu.id_main=mainmenu.id_main
AND submenu.id_main=$r[id_main]");
\t while($w=mysql_fetch_array($sub)){
echo " <li><a href='$w[link_sub]'>$w[nama_sub]</a></li>";
\t }
echo "</ul></li>";}
?>
</ul>
我已經把它分解以嘗試在任何條件下展示他們,而這更相關,但我不能合併它,我不知道我有什麼做,請看這個請
這是第一個條件 - >
<ul class="nav navbar-nav">
<?php
$main=mysql_query("SELECT DISTINCT a.* FROM mainmenu a
INNER JOIN submenu b ON a.id_main = b.id_main AND a.aktif = 'Y'");
while($r=mysql_fetch_array($main)){
echo "<li class='dropdown'><a href='$r[link]' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-expanded='false'>$r[nama_menu]<span class='caret'></span></a><ul class='dropdown-menu' role='menu'>";
$sub=mysql_query("SELECT * FROM submenu, mainmenu
WHERE submenu.id_main=mainmenu.id_main
AND submenu.id_main=$r[id_main]");
while($w=mysql_fetch_array($sub)){
echo " <li><a href='$w[link_sub]'>$w[nama_sub]</a></li>";
}
echo "</ul></li>";}
?>
</ul>
而且Thise第二個條件 - >
<ul class="nav navbar-nav">
<?php
$menu=mysql_query("SELECT DISTINCT a.* FROM mainmenu a
LEFT OUTER JOIN submenu b ON a.id_main = b.id_main WHERE b.id_main is null AND a.aktif = 'Y'");
while($s=mysql_fetch_array($menu)){
echo "<li class='dropdown'><a href='$s[link]'>$s[nama_menu]</a></li>";} ?>
</ul>
我想什麼時候合併內與LEFT OUTER JOIN JOIN是:
if (bla, bla, bla){
echo "Show INNER JOIN";
}else{
echo "Show LEFT OUTER JOIN";
}
我想我需要陣列的2結果打印INNER JOIN和LEFT OUTER JOIN在不同
,和外部沒有..但是,謝謝你的答案..我會嘗試在我的本地.. –