I'm new at web programming was was wondering if you guys could help me. What I want I guess must be easy, but can't really find /how/.
I have my cute little sidebar that isn't even finished and is constantly needing to be changed. I already gave up on updating it until everything is ready:
<!-- sidebar menu -->
<div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
<div class="menu_section">
<h3>General</h3>
<ul class="nav side-menu">
<li><a><i class="fa fa-home"></i> Home <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li>Search</li>
<li>Dashboard</li>
<li>Lookup</li>
</ul>
</li>
<li><a><i class="fa fa-cubes"></i> Inventory <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li>Asset List
<li><a>Asset Management<span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li class="create.php">Create Assets
</li>
<li>Update Assets
</li>
</ul>
</li>
</ul>
</li>
<li><a><i class="fa fa-sitemap"></i> Tickets <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li>Ticket Overview
<li><a>Ticket Management<span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li class="sub_menu">Create a Ticket
</li>
<li>Update a Ticket
</li>
</ul>
</li>
<li><a>User Management<span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li class="sub_menu">User List
</li>
<li>Create a User
</li>
<li>Update a User
</li>
</ul>
</li>
</ul>
<li><a><i class="fa fa-laptop"></i> Loans <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li><a>Loan Management<span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li class="create.php">Create a Loan
</li>
<li>View Loans
</li>
</ul>
</li>
</ul>
</li>
</li>
</ul>
</div>
</div>
<!-- /sidebar menu -->
But the problem is that I'm doing it like an uncultured swine and keeping that in every single page where it is needed. And if I want to make a change, I need to edit every single page.
I was wondering if there was a way to have a class, or something, with my header, sidebar, and footer, and load them across all pages that needed them?
Thank you for your help!
You can extract the sidebar code into its own PHP file (sidebar.php) then include it where you need it with include or include_once
<html>
...
<body>
<?php include './sidebar.php' ?>
...
</body>
</html>
Using include is essentially the same as copy pasting the code into your file. I.e. It will be added where you include the code and it will be evaluated there as well
Its very simple, Save you sidebar in a php file lets call it sidebar.php, and add below code in your other PHP file where you want to show the sidebar.
<?php include_once('sidebar.php');?>
That's it.
Related
Heres how my menu should look like
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Anfrage</a>
</li>
[....]
</ul>
</div
But here is how it actually looks like
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
Home <span class="sr-only">(current)</span>
</li>
<li class="nav-item">
Anfrage
</li>
[....]
</ul>
</div
The key difference is that there is the class 'nav-link' missing.
I dont want to use JQuery, but I would like to write an overwrite for my template.
Mod_menu is probably the right one, is it?
I have been looking through every default file but I did not figure out a way to solve my problem.
Sorry if this has been asked already before, but I tried looking for the answer and couldn't find it.
I am creating a website where a user submits information on their child such as age, school, skill level, etc. when registering.
Once they have completed registering their information and child information they can sign in and go to their dashboard.
I have a menu item that is called "dancers" and the sub menu item should be the dancer/child name that was entered when they registered. another menu item that is also there is "add new dancer".
So what I am trying to do is when they register, upon signing in they should already have the dancer in the dropdown menu for "dancers". which would have been retrieved from the database.
And every time they add a new dancer a new submenu item of that dancer's name should appear.
here is my html menu code:
<div class="row subnav">
<div class="col-sm-12">
<ul>
<li class="li-spacing">Home</li>
<li class="dropdown li-spacing">
<a class="dropdown-toggle" data-toggle="dropdown">Dancers<b class="caret"></b></a>
<ul class="dropdown-menu">
<li>Name</li>
<li class="divider"><hr></li>
<li>Name</li>
<li class="divider"><hr></li>
<li>Add New</li>
</ul>
</li>
<li class="dropdown li-spacing">
<a class="dropdown-toggle" data-toggle="dropdown">Report Cards <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>View all</li>
<li class="divider"><hr></li>
<li>Add New</li>
</ul>
</li>
<li class="li-spacing">History</li>
<li class="li-spacing">Events</li>
<li class="li-spacing">Fun</li>
</ul>
</div>
</div>
I am very new to php, and really need some direction in where to start with this.
any help is much appreciated!
After much research and working on other pages on my website I have finally found a solution that worked perfect for me.
<div class="row subnav">
<div class="col-sm-12">
<ul>
<li class="li-spacing">Home</li>
<li class="dropdown li-spacing">
<a class="dropdown-toggle" data-toggle="dropdown">Dancers<b class="caret"></b></a>
<ul class="dropdown-menu">
<?php
$dancers = "SELECT `dancer_name` FROM `dancers` WHERE name = '$name'";
$dres = mysqli_query($con,$dancers);
if($res==FALSE){
die('there was an error running query [' . $con->error . ']');
}
while($data=mysqli_fetch_array($dres)){
echo '
<li>'.$data["dancer_name"].'</li>
<li class="divider"><hr></li>
';
}
?>
</ul>
</li>
</ul>
I'm attempting to hide the "Register" link in my navbar after the page checks if someone is logged in. I'm using CodeIgniter as my framework.
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Home <span class="sr-only">(current)</span></li>
<li>Reports <span class="sr-only">(current)</span></li>
<li >Register <span class="sr-only">(current)</span></li>
</ul>
I used this to check if someone is logged in before it shows the logout button and it works fine and dandy.
<?php if($this->session->userdata('logged_in')): ?>
<ul class="nav navbar-nav navbar-right">
<li>Logout</li>
</ul>
<?php endif;?>
However, I've seen to run into a snag when trying to do it to hide the Register link. Any help would be much appreciated!
Its should be like this
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Home <span class="sr-only">(current)</span></li>
<li>Reports <span class="sr-only">(current)</span></li>
<?php if(!$this->session->userdata('logged_in')){ ?>
<li >Register <span class="sr-only">(current)</span></li>
<?php } ?>
</ul>
I just need to include an html file (that has my navigation bars for all my pages).
I've tried: <?php htmlentities(file_get_contents("include/navigation.html")); ?>
But nothing shows up at all.
I've checked other questions like this and the code above is always the answer. So why is it not working for me?
Here's my navigation file if needed:
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">[ ] Advanced Web Development</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active">
Home
</li>
<li>
About
</li>
<li>
RĂ©sume
</li>
<li>
Blog
</li>
<li>
Projects
</li>
<li>
Contact
</li>
<!--
<li class="dropdown">
Portfolio <b class="caret"></b>
<ul class="dropdown-menu">
<li>
1 Column Portfolio
</li>
<li>
2 Column Portfolio
</li>
<li>
3 Column Portfolio
</li>
<li>
4 Column Portfolio
</li>
<li>
Single Portfolio Item
</li>
</ul>
</li>
<li class="dropdown">
Blog <b class="caret"></b>
<ul class="dropdown-menu">
<li>
Blog Home 1
</li>
<li>
Blog Home 2
</li>
<li>
Blog Post
</li>
</ul>
</li>
<li class="dropdown">
Other Pages <b class="caret"></b>
<ul class="dropdown-menu">
<li>
Full Width Page
</li>
<li>
Sidebar Page
</li>
<li>
FAQ
</li>
<li>
404
</li>
<li>
Pricing Table
</li>
</ul>
</li>
-->
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
In your above example, php is creating a string from the file, but doing nothing with it. In order to make your code work, you would need to add an echo:
<?php echo htmlentities(file_get_contents("include/navigation.html"));
This is because there are generally three ways that functions can affect things:
Returning a value (what htmlentities does)
Modifying (a) value(s) passed into them (take a look at passing by reference
Echoing something directly or to the output buffer
Since htmlentities returns a value, nothing is sent to output. You would have to either save it to a variable for output later, or echo/print it to the output now.
Alternatively, you could include it as suggested by #David.
While using the echo on your normal code would be sufficent, if you want people to be able to access the HTML, you can include it in a php file itself, anywhere except inside the <?php ?> tag.
htmlentities() does not output to the browser. You still need to echo() or otherwise output.
<?php echo htmlentities(file_get_contents("include/navigation.html")); ?>
Or as suggested in the comments use include() to embed the entire file. PHP will attempt to process the file, so make sure it is error free if it contains any PHP code.
<?php include( "include/navigation.html" ); ?>
try:
<?php
$file = htmlentities(file_get_contents("include/navigation.html"));
echo $file;
?>
I'm trying to build a basic header drop down nav for my three user account types, but they have different options depending on the account type. My code is throwing errors. Code is as follows:
<div class="btn-group pull-right">
<?php if ($this->logged_in):
$is_a = ($this->logged_in_usertype == App_Model_Users::TYPE_A);
$is_b = ($this->logged_in_usertype == App_Model_Users::TYPE_B);
$is_c = ($this->logged_in_usertype == App_Model_Users::TYPE_C);
?>
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-user"></i> <?php echo $this->logged_in_nickname;?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<?php if ($is_b):?>
<li>Page Option One</li>
<li class="divider"></li>
<li>Page Option Two</li>
<li class="divider"></li>
<li>Page Option 3</li>
<li class="divider"></li>
<li>Page Option 4</li>
<li class="divider"></li>
<?php if ($is_a):?>
<li>Account-type 2 Profile</li>
<?php endif;?>
<?php endif;?>
<li>Account Settings</li>
<li class="divider"></li>
<li>Sign Out</li>
</ul>
<?php else:?>
<a class="btn" href="/login">
<i class="icon-user"></i> Register / Login
</a>
<?php endif;?>
</div>
I think my problem is the 2nd if statement for (if is_a)... but I'm not sure - I'm rather new to php. Could someone please help me with the correct way to construct this if statement w/ as little changes as possible to the code?
Can you post the actual error here, to inspect.
and you have a syntax error on line 32
<?php else:?>
And the second if is inside the fist if statment