how to view submenu on click using php,html - php

I'm trying to view submenu after click on parent.
Classes->Primary School->(Grade1,Grade2,Grade3,Grade4,Grade5,Grade6)
Classes->Middle School->(Grade7,Grade8,Grade9)
Classes->Secondary School->(Grade10,Grade11,Grade12)
<div class="collapse navbar-collapse" id="main-navigation">
<ul class="nav navbar-nav navbar-right">
<?php foreach ($data as $menu) { ?>
<?php if(!$menu->children) { ?>
<li><?php echo $menu->name; ?></li>
<?php }
else {
?>
<li class="dropdown open">
<a href="#" class="dropdown-toggle " data-toggle="dropdown">
<?php echo $menu->name; ?>
<span class="fa fa-angle-down"></span>
</a>
<ul class="dropdown-menu open" role="menu">
<?php
foreach ($menu->children as $child) {
?>
<li><?php echo $child->name; ?></li>
<?php
foreach ($child->children as $sub_child) {
?>
<li class="dropdown-submenu">
<?php echo $sub_child->name; ?><span class="fa fa-angle-down"></span>
<ul class="dropdown-submenu" role="menu">
<?php } ?>
<?php } ?>
</ul>
</li>
<?php } ?>
<?php } ?>
</ul>
</li>
</ul>
</div>
The result:
Problem with result
I want to view Grade 1 to Grade 6 after click on Primary school and from Grade 7 to Grade 9 after click on Middle school ...
Please help!

You have an open <ul class="dropdown-submenu" role="menu"> tag without any <li> or <a>'s being generated inside of it. Then you close two each statements before closing the <ul> tag.
<?php foreach ($child->children as $sub_child) { ?>
<li class="dropdown-submenu">
<a href="#" style="color:black;" class="dropdown-toggle " data-toggle="dropdown">
<?php echo $sub_child->name; ?><span class="fa fa-angle-down"></span>
</a>
<ul class="dropdown-submenu" role="menu">
<?php } ?>
<?php } ?>
</ul>
</li>
This will be causing all sorts of unintended markup output. Fix that and it should fix your problem. If not, you'll atleast be a lot closer.

Related

bootstrap multilevel dropdown in navbar has unwanted empty space

I have bootstrap multilevel drop down navbar. when I click on the button I want the sub menu to drop right side of the list but it is overlapping last option. can anyone suggest me how to do it?
<ul class="nav navbar-nav col-lg-4">
<li class="active dropdown yamm-fw">
Home
</li>
<li class="dropdown"><a class="dropdown-toggle" data-hover="dropdown"
href="#"> category <span class="caret"></span> </a>
<ul class="dropdown-menu dropright">
<?php $sql=mysqli_query($con,"select id,categoryName from category
limit 10");
while($row=mysqli_fetch_array($sql))
{
$category_name=$row['categoryName'];
if ( $category_name == "Clothing")
{ ?>
<li class="dropdown yamm btn-group">
<a class="dropdown-toggle " data-toggle="dropdown" href="#"> <?php echo
$category_name; ?><span class="caret"></span></a>
<ul class="dropdown-menu dropright">
<?php $sql1=mysqli_query($con,"select id,subcategory from subcategory1
where categoryid=" .$row['id']);
while($row1=mysqli_fetch_array($sql1))
{ ?>
<li class="dropdown yamm">
<a href="category.php?cid=<?php echo $row1['id'];?>"> <?php echo
$row1['subcategory'];?></a>
</li>
<?php } ?>
</ul>
</li>
<?php }
else
{ ?>
<li class="dropdown yamm">
<a href="category.php?cid=<?php echo $row['id'];?>"> <?php echo
$row['categoryName'];?></a>
</li>
<?php
}
} ?>
</ul>
You may overcome this problem by writing the CSS the value of paddings.
.nav li {padding-top: 5px; padding-bottom: 5px;}
Also, have look at line-height property it might be create some problem. on some cases.

Show active navigation for current page

i'm having some problems with my html, php code. With this code, my nav will show the active li but the other pages which are not active won't have style or links.
<!--/. PHP "active" -->
<?php
$current_url = basename($_SERVER['PHP_SELF']);
$active = "class=\"active-menu\"";
?>
<!--/. PHP "active" -->
<nav class="navbar-default navbar-side" role="navigation">
<div class="sidebar-collapse">
<ul class="nav" id="main-menu">
<li>
<?php if ($current_url == "home.php") { ?>
<a <?php echo $active;?> href="home.php"><?php } ?><i class="fa fa-dashboard"></i> Dashboard</a>
</li>
<li>
<?php if ($current_url == "new.php") { ?>
<a <?php echo $active;?> href="new.php"><?php } ?><i class="fa fa-qrcode"></i> Nieuw item toevoegen</a>
</li>
<li>
<?php if ($current_url == "show.php") { ?>
<a <?php echo $active;?> href="show.php"><?php } ?><i class="fa fa-qrcode"></i> Bekijk inventaris</a>
</li>
<li>
<?php if ($current_url == "profile.php") { ?>
<a <?php echo $active;?> href="profile.php"><?php } ?><i class="fa fa-user"></i> Gebruikersprofiel</a>
</li>
<li>
<i class="fa fa-sitemap"></i> Gebruikers<span class="fa arrow"></span>
<ul class="nav nav-second-level">
<li>
Beheerders
</li>
<li>
ICT - Verantwoordelijken
</li>
<li>
Raadplegers
</li>
</ul>
</li>
<li>
<?php if ($current_url == "empty.php") { ?>
<a <?php echo $active;?> href="empty.php"><?php } ?><i class="fa fa-fw fa-file"></i> Lege pagina</a>
</li>
</ul>
</div>
</nav>
the pages with no styling will also not have a link. The active-menu class has the styling.
Your if condition it is wrong.
Try something like this in every <li>.
<li>
<a <?php echo $current_url == "home.php" ? $active : ''; ?> href="home.php"><i class="fa fa-dashboard"></i> Dashboard</a>
</li>
<li>
<a href="new.php" <?php if ($current_url == "new.php") {echo $active;}?>>
<i class="fa fa-qrcode"></i> Nieuw item toevoegen
</a>
</li>
Put your list like this
You should make another class, like $not_active = "class=\"not-active-menu\"";
And add that to your code
<li>
<a href="something.php" <?php if ($current_url == "something.php") {echo $active;} else { echo $not_active; }?>>
<i class="fa fa-qrcode"></i> something
</a>
</li>

How To Display In A List Using PHP

How do you repeatedly display the ID numbers in PHP then in a list?
This is the code I have in View
<ul class="dropdown-menu" role="menu">
<li><?php echo ?></li>
</ul>
In Controller
$query=$this->mdl_mainmenu->notif_items();
$data['notifs'] = $query;
$this->load->view('vw_main_menu',$data);
In Model
function notif_items(){
$user = $this->session->userdata("username");
$this->csbrms->select("deleted_user_request.sdp_no,
deleted_user_request.approval_status");
$this->csbrms->from('deleted_user_request');
$this->csbrms->join('m_employee_masters', 'm_employee_masters.emp_no = user_request.emp_no');
$this->csbrms->where('deleted_user_request.created_by',$user);
$this->csbrms->where('deleted_user_request.approval_status' , 'Closed');
$this->csbrms->where('deleted_user_request.approval_status' , 'Resolved');
$query = $this->csbrms->get();
return $query->result();
}
changed ul tag to :
<ul class="dropdown-menu" role="menu">
<?php foreach($vw_main_menu['notifs'] as $row):?>
<li>
<?php echo $row['deleted_user_request.sdp_no']?>
</li>
<?php endforeach;?>
</ul>
<ul class="dropdown-menu" role="menu">
<?php foreach($notifs as $row):?>
<li>
<?php echo $row->deleted_user_request.sdp_no; ?>
</li>
<?php endforeach;?>
</ul>

PHP with or logical and adding a class to the li global navigation

I'm in the process on covering the navigation bar on all the pages to a global navigation with the PHP. I'm using PHP also to add a class and show the current page.
The challenge that I'm facing is the parent navigation selection. It's underlined when it's on the child page and the sub-nav is also selected. Such as I'm on the "History" page, child page to the "About Us" page. Both are underlined.
The challenge that I'm facing is when I move over to the next page, "Service Areas" or any of it's children, the "About Us" nav selection is still underline. I'm trying to use the || logic to prevent that from happening.
Below is the following code:
<li class="dropdown <?php if ($thisPage=='About Us'||'History'||'Mission Values'||'Process'||'Our People'||'Testimonials'||'Capstone Cares') echo 'active'; ?>">
Is there a way that I can deselect the parent nav when I'm under a different nav section?
Website is http://capstone.dgpehrson.com
Here is the rest of the code...
On individual pages I'm adding:
<?php $thisPage="About Us"; ?>
I'm changing the name according to the page.
Here is the Navigation code:
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown <?php if ($thisPage=='About Us' || 'History' || 'Mission Values' || 'Process' || 'Our People' || 'Testimonials' || 'Capstone Cares') echo 'active'; ?>">
About Us<span class="caret"></span> <!-- Alink extentions that's been removed: data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" -->
<ul class="dropdown-menu">
<li <?php if ($thisPage=="History") echo "class=\"active\""; ?>>History</li>
<li <?php if ($thisPage=="Mission Values") echo "class=\"active\""; ?>>Mission & Values</li>
<li <?php if ($thisPage=="Process") echo "class=\"active\""; ?>>Process</li>
<li <?php if ($thisPage=="Our People") echo "class=\"active\""; ?>>Our People</li>
<li <?php if ($thisPage=="Testimonials") echo "class=\"active\""; ?>>Testimonials</li>
<li <?php if ($thisPage=="Capstone Cares") echo "class=\"active\""; ?>>Capstone Cares</li>
</ul>
</li>
<li class="dropdown <?php if ($thisPage=='Service Areas'||'Apartments'||'Capital'||'Development Services'||'Manufactured Housing'||'Complimentary') echo 'active'; ?>">
Service Areas<span class="caret"></span> <!-- Alink extentions that's been removed: data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" -->
<ul class="dropdown-menu">
<li <?php if ($thisPage=="Apartments") echo "class=\"active\""; ?>>Apartments</li>
<li <?php if ($thisPage=="Capital") echo "class=\"active\""; ?>>Capital</li>
<li <?php if ($thisPage=="Development Services") echo "class=\"active\""; ?>>Developement Services</li>
<li <?php if ($thisPage=="Manufactured Housing") echo "class=\"active\""; ?>>Manufactured Housing</li>
<li <?php if ($thisPage=="Complimentary") echo "class=\"active\""; ?>>Complimentary Value Analysis</li>
</ul>
</li>
<li class="dropdown">
Offerings<span class="caret"></span> <!-- Alink extentions that's been removed: data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" -->
<ul class="dropdown-menu">
<li>Apartment</li>
<li>Manufactured Housing</li>
<li>Multi-family Land</li>
</ul>
</li>
<li class="dropdown">
Market Reports<span class="caret"></span> <!-- Alink extentions that's been removed: data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" -->
<ul class="dropdown-menu">
<li>Florida</li>
<li>Kentucky</li>
<li>North Carolina</li>
<li>South Carolina</li>
<li>Tennessee</li>
<li>Virginia</li>
</ul>
</li>
<li>News</li>
<li>Careers</li>
<li>Contact Us</li>
</ul>
You have to have the compare between each 'or'. The string is just evaluating to a true.
if ($thisPage=='About Us'||$thisPage=='History'||$thisPage=='Mission Values'||$thisPage=='Process'||$thisPage=='Our People'||$thisPage=='Testimonials'||$thisPage=='Capstone Cares') echo 'active';

trying to get foreach loop to display items with subitems correctly in list items

I am really trying to get this to work and am close:
It loops through the array and does create the submenus (with an error albeit) but:
the first menu with submenu items appears correctly but on the second menu that has a submenu items it repeats the first submenu items and then the second submenu items..... what am I missing?
Any help would be greatly appreciated.
<ul class="nav navbar-nav">
<?php
$html = new cacheHTML('topmenu');
if(!$html->isCached){
$menuitems = getMenuLevelsArray(25, 1 , 1);
$submenuI = "0";
foreach($menuitems as $item){
if($item['submenu']){
$subs[$submenuI] = $item['submenu'];
}
?>
<li <?php if($subs[$submenuI]){ ?> class="dropdown" <?php }?>>
</span> <?php }?>
<!-- submenu begins here -->
<?php foreach($subs as $submenuI => $menu){ ?>
<ul class="dropdown-menu" role="menu">
<li>
<?php
for($a=0; $a < count($menu); $a++){
?>
<a href="<?php echo $menu[$a]['url']; ?>" <?php if(!$menu[$a+1]){ echo "class='last'"; } ?>><?php echo $menu[$a]['text']; ?></a>
<?php } ?>
</li>
</ul>
<?php $submenuI++; } ?>
</li>
<?php
}
?>
<?php } $html->show(); ?>
</ul>
`<ul class="nav navbar-nav">
<li> Home <br>
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/layout.php</b> on line 95<br>
</li>
<li class="dropdown open">
About<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>
About
Board of Directors
Structure
</li>
</ul>
</li>
<li>
Standards & Codes
<ul class="dropdown-menu" role="menu">
<li>
About
Board of Directors
Structure
</li>
</ul>
</li>
<li class="dropdown">
Resources <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>
About
Board of Directors
Structure
</li>
</ul>
<ul class="dropdown-menu" role="menu">
<li>
Frequently Asked Questions
News Archives
Resource Links
Safety Alerts
</li>
</ul>
</li>
<li>Contact Us
<ul class="dropdown-menu" role="menu">
<li>
About
Board of Directors Structure
</li>
</ul>
<ul class="dropdown-menu" role="menu">
<li>
Frequently Asked Questions
News Archives
Resource Links
Safety Alerts
</li>
</ul>
</li>
</ul>`
Under the first "foreach" loop you should reset your $subs array to make sure it's empty. Otherwise it gets down to the second loop, sees the old "$subs" from the previous loop, and loops through it again:
foreach ( $menuitems as $item ) {
$subs = array();
if ($item ['submenu']) {
$subs [$submenuI] = $item ['submenu'];
}
...
I found the mixture of PHP and HTML hard to read, so I rewrote the code to make it easier for my eyes:
$html = new cacheHTML ( 'topmenu' );
if (! $html->isCached) {
$menuitems = getMenuLevelsArray ( 25, 1, 1 );
$submenuI = "0";
foreach ( $menuitems as $item ) {
if ($item ['submenu']) {
$subs [$submenuI] = $item ['submenu'];
}
echo '<li';
if($subs[$submenuI]){
echo 'class="dropdown"';
}
echo ">
<a href='{$item['url']}'";
if($subs[$submenuI]){
echo 'class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"';
}
echo ">{$item['text']}";
if($subs[$submenuI]){
echo '<span class="caret"></span>';
}
echo '</a> <!-- submenu begins here -->
';
foreach($subs as $submenuI => $menu){
echo '<ul class="dropdown-menu" role="menu">
<li>
';
for($a = 0; $a < count ( $menu ); $a ++) {
echo "<a href='{$menu[$a]['url']}'";
if(!$menu[$a+1]){
echo "class='last'";
}
echo ">{$menu[$a]['text']}</a>
";
}
echo '</li>
</ul>
';
$submenuI++;
}
echo '</li>';
}
}
$html->show(); ?>
</ul>
I hope this helps!
Finally got it...
I need to learn me some more PHP if statements and foreach's
here is what I did:
<ul class="nav navbar-nav">
<?php
$html = new cacheHTML('topmenu');
if(!$html->isCached){
$menuitems = getMenuLevelsArray(25, 1 , 1);
$submenuI = "0";
foreach($menuitems as $item){
if($item['submenu']){
$subs[$submenuI] = $item['submenu'];
}
?>
<li <?php if($subs[$submenuI]){ ?> class="dropdown" <?php }?>>
</span> <?php }?>
<!-- submenu begins here -->
<?php foreach($subs as $submenuI => $menu){ ?>
<ul class="dropdown-menu" role="menu">
<li>
<?php
for($a=0; $a < count($menu); $a++){
?>
<a href="<?php echo $menu[$a]['url']; ?>" <?php if(!$menu[$a+1]){ echo "class='last'"; } ?>><?php echo $menu[$a]['text']; ?></a>
<?php } ?>
</li>
</ul>
<?php $submenuI++; } ?>
</li>
<?php
}
?>
<?php } $html->show(); ?>
</ul>

Categories