Writing my first php application. I’m stuck on how to add either a loop or conditional statement…I’m adding my sites navigation from Oracle database queries…a primary and secondary navigation…I’ve noted in my code where I need an if or while statement to decide if a ul tag is written. I only want the ul class = sub tag written and subsequent li list when I have secondary navigation under the primary navigation. Any suggestion that would point me in the right direction? Thanks in advance…
`
$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>";
}
`
I’m not familiar with the Oracle driver, but you probably want the
oci_num_rows()function. After you issue the second query, you should be able to call that function, and check if it returns a non-zero value:Actually, you should probably also verify that oci_execute() returns true, so maybe something like: