编写我的第一个 php 应用程序。我被困在如何添加循环或条件语句...我正在从 Oracle 数据库查询添加我的站点导航...主要和辅助导航...我在我的代码中注意到我需要一个if 或 while 语句来决定是否写入ul标签。当我在主导航下有辅助导航时,我只希望编写ul class = sub标签和后续的li列表。有什么建议可以为我指明正确的方向吗?提前致谢...
`
$t1_query = "SELECT * FROM PLUS_NAV_T1 ORDER BY POSITION ASC";
$t1_parse = oci_parse($sm_conn, $t1_query);
oci_execute ($t1_parse);
/* Add query error catch*/
while ($t1_row = oci_fetch_array($t1_parse, OCI_ASSOC)) {
echo "<li><a href=\"#\" title=\"\" class=\"exp\"><span>{$t1_row["T1_NAME"]}</span></a>";
$t2_query = "SELECT * FROM PLUS_NAV_T2 WHERE T1_ID_FK = {$t1_row["ID_PK"]} ORDER BY POSITION ASC ";
$t2_parse = oci_parse($sm_conn, $t2_query);
oci_execute ($t2_parse);
/* Add query error catch*/
/*Need a conditional here so ul tag is only written when the primary nav has secondary nav*/
echo "<ul class=\"sub\">";
while ($t2_row = oci_fetch_array($t2_parse, OCI_ASSOC)) {
echo "<li><a href=\"#\" title=\"\" style=\"color\">{$t2_row["T2_NAME"]}</a></li>";
}
echo "</ul>";
echo "</li>";
}
`