Passing value from dropdown bootstrap to next php page - php

How do i pass a value on dropdown bootstrap to the next page. There several options to choose and obviously it would be a waste of time making multiple same layout page but with different contents. How do i pass the value from dropdown to the next php page so that the next page can load the data based on that value.
I've seen some examples using the form method but it ruins the dropdown layout.Using bootstrap 3.3.7. Thanks in advance
<div class="container-fluid">
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Admin <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Register Donee</li>
</ul>
</li>
<li class="">Home</li>
<li>How It Works</li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">State <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Johor</li>
<li>Selangor</li>
<li>Melaka</li>
<li>Penang</li>
<li>Perak</li>
<li>Pahang</li>
<li>Kedah</li>
<li>Kelantan</li>
<li>Terengganu</li>
<li>Negeri Sembilan</li>
<li>Perlis</li>
<li>Sabah</li>
<li>Sarawak</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>

href should be something like
<li>Johor</li>
<li>Selangor</li>
<li>Melaka</li>
in page.php use $_GET['sel'] to get the selected value

Related

How to create a new menu item with information from database php and sessions

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>

Make a global sidebar?

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.

php include html file?

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;
?>

highlight active page in navigation bar with common header

I'm new in the web programming. I made a simple website with a common header. My header is in a folder called inc/common_header.php and i included this header in all my other pages.
The header is working good so far, but i want to put different color in the nav menu for the current page. I tried this solution:
<?php
if (strpos($_SERVER['PHP_SELF'], 'about.php')) echo 'class="current"';
?>
This solution is working good but my problem is that i have the navigation bar in a separate page and when i click, the result is always the same inc/common_header.php and not the current page.
Here is my code:
common_header.php
<nav class="navigation-bar fixed-top">
<nav class="navigation-bar-content">
<a class="element brand" href="/"><span class="icon-grid-view"></span> COMPANY NAME</a>
<span class="element-divider"></span>
<a class="element brand" href="/"><span class="icon-home"></span> HOME</a>
<div class="element">
<a class="dropdown-toggle" href="#"><span class="icon-printer"></span> SERVICES</a>
<ul class="dropdown-menu" data-role="dropdown">
<li>SERVICE 1</li>
<li>SERVICE 2</li>
<li>SERVICE 3</li>
<li class="divider"></li>
<li>SERVICE 4</li>
<li>SERVICE 5</li>
<li class="divider"></li>
<li>SERVICE 6</li>
<li>SERVICE 7</li>
</ul>
</div>
<div class="element">
<a class="dropdown-toggle" href="#"><span class="icon-printer"></span> CALCULATOR</a>
<ul class="dropdown-menu" data-role="dropdown">
<li>HOME</li>
</ul>
</div>
<a class="element brand" href="about.php"><span class="icon-printer"></span> ABOUT</a>
<div class="element place-right">
<a class="dropdown-toggle" href="#"><span class="icon-cog"></span> SETTINGS</a>
<ul class="dropdown-menu place-right" data-role="dropdown">
<li>MY ACCOUNT</li>
<li>MY PRODUCTS</li>
<li class="divider"></li>
<li>LOG OUT</li>
</ul>
</div>
<span class="element-divider place-right"></span>
<button class="element image-button image-left place-right"> USERNAME <img src="img/me.jpg"/></button>
</nav>
Thanks in advance for your help. I will appreciate it.
I will assume that your problem is this:
You have a common section of the pages on your site (the header) in a file 'common_header'. You include that file 'common_header' in all the pages of your site (for example: home, about, services, products, contact). But in one of those pages (for example: contact) and just in that page, you want to show the header with a different style.
If that is your issue, my solution is:
In your 'common_header' page use this php code instead of the one you have:
if(isset($specialPage) && $specialPage == "this is the special page"){
echo 'class="current"';
};
Then, in your 'contact' page (that I'm using as an example), you write this before including your header page:
$specialPage = "this is the special page";
include("your header page");
Again, if this is not what you want, I'm apologize for misunderstanding your question.
Try changing one of your href to about.php and see if it works. Example:
<ul class="dropdown-menu" data-role="dropdown">
<li>About</li>
//etc
As it stands your hyperlinks go to your index.php, which gives that same value to the PHP_SELF super, thus never agreeing with about.php. At least that what I can see by this limited code sample. If that doesn't work, please edit your question to include the output of $_SERVER['PHP_SELF'], which should give you the clue anyway.
Moreover there's no reason to use strpos when comparing strings; use the === operator instead, which checks if arguments are of the same type as well as if they have the same value.

Dynamic dropdown menu using php with twitter bootstrap

Thank you for reading... I have a 2 layer of navigation. which sort the content by good, bad and comment count. if user clicks on good it will bring another nav which is sort the content by time. such as today, last one week, last one month.
I can add class='active' using $_SERVER['PHP_SELF'] but twitter bootsrap dropdown menu does not have simple class='active' it is complicated. I am not able to come up with a solution. should I use for? foreach? I don't know. please see the html command in the code. this is my code.
<ul class="nav nav-tabs">
<li <?php if (basename($_SERVER['PHP_SELF']) == '/?Top'): ?> class="active"<?php endif; ?>>Top Content</li>
<li <?php if (basename($_SERVER['PHP_SELF']) == '/?Bad'): ?> class="active"<?php endif; ?>>Bad Content</li>
<li <?php if (basename($_SERVER['PHP_SELF']) == '/?Comments'): ?> class="active"<?php endif; ?>>Most Commented</li>
<!-- It's confusing me when It comes here... because as you see active option is not li tag. it's bunch of html code and also any url bellow can ben any of those up -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-time"></i> Today <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="URL=week" />Last 1 Week</a></li>
<li><a href="URL=month" />Last 1 Month </a></li>
<li><a href="URL=all" />All</a></li>
</ul>
</li>
</ul>
html commend: It's confusing me when It comes here... because as you see active li is not li it's bunch of html code and also also any url below can be any of those up
You can use the "active" class for the outter li (the one has class "dropdown") and another "active" class in your child dropdown.
This is an example
<ul class="nav nav-tabs">
<li class="">Home</li>
<li>Help</li>
<li class="dropdown active">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li class="active">Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
A live demo in JSBin

Categories