ricky spires Posted September 13, 2011 Share Posted September 13, 2011 Hello. I recently posted about getting my top nav to work which it does now (with thanks) but im having trouble getting my side navs to work. i have tried various things but i think its just a case of getting the where clause right. see what you think. any help would be great these are my files. includes/navL1.php - which does the top navigation includes/navL2.php - which does the left navigation main includes/navL3.php - which does the left navigation sub admin/layouts/admin_topnav.php admin/layouts/admin_leftnav.php admin/layouts/index.php ok so. admin topnav.php code looks like this and works <?PHP require_once("../includes/initialize.php"); global $topNav; global $pageName; ?> <div id="navWrapper"> <?PHP $topNav = navL1::find_all(); ?> <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach($topNav as $topNavs): ?> <li><a <?PHP echo ($pageName == $topNavs->title ? 'class="selected"' : '')?> href="<?PHP echo $topNavs->title; ?>.php" id="<?PHP echo $topNavs->title; ?>"><?PHP echo $topNavs->title; ?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #ddtabs3--> </div><!-- #navWrapper--> now i need when a top nav is selected i need the correct left nav main and subs to show. this is how my left nav looks at the moment <?PHP require_once("../includes/initialize.php"); global $topNav; global $pageName; ?> SOME ACCORDION SCRIPT GOES HERE <div class="arrowlistmenu"> <?PHP $nav1 = navL1::find_all(); $nav2 = navL2::find_by_nav(); $nav2 = navL2::find_by_nav(); ?> <?PHP foreach($nav2 as $nav2s): ?><h3 class="menuheader expandable"> // MAIN LEVEL <li><a <?PHP echo ($pageName == $nav2s->title ? 'class="selected"' : '')?> href="<?PHP echo $nav2s->title; ?>.php" id="<?PHP echo $nav2s->title; ?>"><?PHP echo $nav2s->title; ?></a></li></h3> <?PHP endforeach; ?> // SUB LEVEL <ul class="categoryitems"> <?PHP foreach($nav3 as $nav3s): ?> <li><a <?PHP echo ($pageName == $nav3s->title ? 'class="selected"' : '')?> href="<?PHP echo $nav3s->title; ?>.php" id="<?PHP echo $nav3s->title; ?>"><?PHP echo $nav3s->title; ?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #End arrowlistmenu --> <img src="images/wrapper/loading.gif" alt="loading..." id="Pageloading" height="28" width="28" style="visibility:hidden;float:left;" /> this is the code im trying to get to work in my includes files that i can seem to get my head around includes/navL2.php public static function find_by_nav(){ global $database; global $topNav; $sql = "SELECT * FROM ".self::$table_name." WHERE title="$topNav" LIMIT 1"; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } the find_by_sql($sql) looks like this but i dont think you need it public static function find_by_sql($sql){ global $database; $results_set = $database->query($sql); $object_array = array(); while($row = $database->fetch_array($results_set)){ $object_array[] = self::instantiate($row); } return $object_array; } im trying to use the same code to pull the sub levels inside includes/navL3.php if any of this makes sense please could you point out whats wrong thanks ricky Link to comment https://forums.phpfreaks.com/topic/247018-need-help-getting-my-side-nav-to-work-with-loops-depending-on-top-nav/ Share on other sites More sharing options...
Pandemikk Posted September 13, 2011 Share Posted September 13, 2011 $topNavs->title and $nav2s->title will need to be named the same thing if you expect that code to work. Overall your code is gigantic mess and it be a lot easier to help you if you showed us exactly where the problem lies in your code and what you need to be done. You should also be debugging a bit. Make sure $pageName evaluates to the same thing in your top nav and left nav. Link to comment https://forums.phpfreaks.com/topic/247018-need-help-getting-my-side-nav-to-work-with-loops-depending-on-top-nav/#findComment-1268598 Share on other sites More sharing options...
ricky spires Posted September 13, 2011 Author Share Posted September 13, 2011 ok. i have done some re-jigging and tried a couple of things but im not there yet. basically all i need to do is pass the ids in the mysql db i have: navL1 navL2 - this has a row called navL1_id navL3 - this has a row called navL2_id i have managed to echo the top navigation id but its echoing the last tab id which is 5. how do i get the id of the selected tab ? i tried this but that does not work echo $topNavs->id 'class="selected"'; from this code <?PHP require_once("../includes/initialize.php"); global $topNavs; global $pageName; ?> <div id="navWrapper"> <?PHP $topNav = navL1::find_all(); ?> <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach($topNav as $topNavs): ?> <li><a <?PHP echo ($pageName == $topNavs->title ? 'class="selected"' : '')?> href="<?PHP echo $topNavs->title; ?>.php" id="<?PHP echo $topNavs->title; ?>"><?PHP echo $topNavs->title; echo $topNavs->id;?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #ddtabs3--> </div><!-- #navWrapper--> then pass that in a global to the left navigation using global $topNavs; thanks rick Link to comment https://forums.phpfreaks.com/topic/247018-need-help-getting-my-side-nav-to-work-with-loops-depending-on-top-nav/#findComment-1268620 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.