i am trying to make my navigation dynamic but i' having a few problems. here is my code.
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "index.php")) {
echo '<li class="active">
<a href="index.php">
<span class="meta">
<span class="text">HOME</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
} else{
echo '<li>
<a href="index.php">
<span class="meta">
<span class="text">HOME</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
}
?>
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "services.php")) {
echo '<li class="dropdown active">
<a href="#" class="dropdown-toggle " data-toggle="dropdown">
<span class="meta">
<span class="text">SERVICES</span>
<span class="caret"></span>
</span>
</a>
<ul class="dropdown-menu">
<li>Service A</li>
<li>Service B</li>
<li>Service C</li>
<li>Service D</li>
</ul>
</li>';
} else{
echo '<li class="dropdown">
<a class="dropdown-toggle " data-toggle="dropdown">
<span class="meta">
<span class="text">SERVICES</span>
<span class="caret"></span>
</span>
</a>
<ul class="dropdown-menu">
<li>Service A</li>
<li>Service B</li>
<li>Service C</li>
<li>Service D</li>
</ul>
</li>';
}
?>
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "data-catalog.php")) {
echo '<li class="active">
<a href="data-catalog.php">
<span class="meta">
<span class="text">DATA CATALOG</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
} else{
echo '<li>
<a href="data-catalog.php">
<span class="meta">
<span class="text">DATA CATALOG</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
}
?>
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "about.php")) {
echo '<li class="active">
<a href="about.php">
<span class="meta">
<span class="text">ABOUT US</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
} else{
echo '<li>
<a href="about.php">
<span class="meta">
<span class="text">ABOUT US</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
}
?>
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "contact.php")) {
echo '<li class="active">
<a href="contact.php">
<span class="meta">
<span class="text">CONTACT US</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
} else{
echo '<li>
<a href="contact.php">
<span class="meta">
<span class="text">CONTACT US</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
}
?>
After running, i realise that on the home page, the services list drops down successfully but it doesnt do so when i'm on other pages. Can anybody help me?
I think the code and its structure is perfect. There is nothing absolute wrong with the code. Just uploaded the files onto the web and everything is working perfect. I checked plugins and all and i realised that the file only needs to be on the internet to run smoothly.
Related
hope you are all doing well, i have just face a problem. i make my website online. everything working well expect navbar toggler icon. it is not working on mobile device. it is working well on desktop
here is my code
<nav class="navbar navbar-expand-md navbar-light bg-light sticky-top">
<div class="container-fluid">
<a class="navbar-brand" href="index.php"><img src="./assests/images/logo.png" class="logo ml-5" alt="file not found" /> </a>
<button class="navbar-toggler " type="button" role="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"> </span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item <?php if($page == 'home') echo 'active' ?>">
<a class="nav-link " href="index.php"><i class="mr-2 fas fa-home"> </i>Home </a>
</li>
<li class="nav-item <?php if($page == 'about') echo 'active' ?>">
<a class="nav-link" href="about.php"><i class="mr-2 fas fa-users"> </i> About Us</a>
</li>
<li class="nav-item dropdown <?php if($page == 'products') echo 'active' ?>" >
<a class="nav-link dropdown-toggle dropdown-toggle-split" href="products.php" data-toggle="dropdown" id="dropedownMenuButton"aria-expanded="false" aria-hospopup="true" >
<i class="mr-2 fas fa-wrench"> </i>Products
</a>
<ul class="dropdown-menu" aria-labelledby="dropedownMenuButton">
<li class="list-group-item">
<a class="dropdown-item" href="bolts-screws.php"> Bolts/Screws </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="nuts.php"> Nuts </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="washers.php"> Washers </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="screws.php"> Screws </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="socket-bolt-screws.php"> Socket Bolts/Screws </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="anchor-fastener.php"> Anchor Fasteners </a>
</li>
</ul>
</li>
<li class="nav-item <?php if($page == 'connect') echo 'active' ?>">
<a class="nav-link" href="connect.php"><i class="mr-2 fas fa-user"> </i> Contact us </a>
</li>
</ul>
</div>
</div>
</nav>
you can check my website also
http://rudrafasteners.com/
It seems you don't add Javascript at your head. Add the followings lines to your HTML <head> tag (Jquery and Bootstrap JS):
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
I have directory like this "localhost/site/folder1/file.php", I need to access file.php from "site" directory this way
href = "folder1/file.php"
unfortunately it takes me to
href = "folder1/folder1/file.php"
and when I access "index.php" file located in "site" directory from "folder1", this way
href = "../index.php"
it takes me to root directory in c: I mean this way
href = "localhost/index.php".
I have stacked with this problem for two days now, please any one to help me get out this.
Note: I am using bootstrap framework
More edit...
here is the full code.
<section>
<section class="hbox stretch">
<!-- .aside -->
<aside class="bg-black dk nav-xs aside hidden-print" id="nav">
<section class="vbox">
<section class="w-f-md scrollable">
<div class="slim-scroll" data-height="auto" data-disable-fade-out="true" data-distance="0" data-size="10px" data-railOpacity="0.2">
<!-- nav -->
<nav class="nav-primary hidden-xs">
<ul class="nav bg clearfix" data-ride="collapse">
<!--<li class="hidden-nav-xs padder m-t m-b-sm text-xs text-muted">
Discover
</li>-->
<li>
<a href= "../index.php">
<i class="icon-home icon text-success"></i>
<span class="font-bold">Home</span>
</a>
</li>
<li>
<a href="#" class="auto">
<span class="pull-right text-muted">
<i class="fa fa-angle-left text"></i>
<i class="fa fa-angle-down text-active"></i>
</span>
<i class="icon-music-tone-alt icon text-info"></i>
<span class="font-bold">Audios</span>
</a>
<ul class="nav dk text-sm">
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Speaches</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Preaches</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Interviews</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Songs</span>
</a>
</li>
</ul>
</li>
<li>
<a href="#" class="auto">
<span class="pull-right text-muted">
<i class="fa fa-angle-left text"></i>
<i class="fa fa-angle-down text-active"></i>
</span>
<i class="icon-book-open icon text-primary-lter"></i>
<span class="font-bold">Writtings</span>
</a>
<ul class="nav dk text-sm">
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Books</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Jounals</span>
</a>
</li>
</ul>
</li>
<li>
<a href="#">
<i class="icon-users icon text-primary-lter"></i>
<span class="font-bold">Artists</span>
</a>
</li>
<li>
<a href="#">
<i class="icon-film icon text-info-dker"></i>
<span class="font-bold">Albums</span>
</a>
</li>
<li class="m-b hidden-nav-xs"></li>
</ul>
<ul class="nav" data-ride="collapse">
<li class="hidden-nav-xs padder m-t m-b-sm text-xs text-muted">
User Account
</li>
<li>
<?php
if(!isset ($_SESSION['email'])){
echo "
<a href='../signin.php' class='auto'>
<i class='icon-login icon'>
</i>
<span>Signin</span>
</a>
</li>
<li >
<a href='../signup.php' class='auto'>
<i class='fa fa-smile-o'>
</i>
<span>Signup</span>
</a>
</li>
";
}else{
echo "
<a href='../signout.php' class='auto'>
<i class='icon-logout icon'>
</i>
<span>SignOut</span>
</a>
</li>";
if (!isset($_SESSION['admin_name'])) {
echo "
<li >
<a href='profile.php' class='auto'>
<i class='fa fa-smile-o'>
</i>
<span>My profile</span>
</a>
</li>
";
}else{
echo "
<li >
<a href='MembersManagement.php' class='auto'>
<i class='fa fa-edit'>
</i>
<span>Manage Member</span>
</a>
</li>
<li >
<a href='admin.php' class='auto'>
<i class='fa fa-edit'>
</i>
<span>My Dashboard</span>
</a>
</li>
";
}
}
?>
</ul>
</nav>
<!-- / nav ---->
</div>
</section>
And the problem is on this line
<nav class="nav-primary hidden-xs">
When I remove "nav-primary" everything is doing fine with the anchors () but it changes the appearance and arrangements in the section, what should I do, I am new to bootstrap frameworks.
If you are having problem with relative urls, you can try doing with absolute urls like :
href = "localhost/site/folder1/file.php".
and for the other one you can do same:
href = "localhost/site/index.php
Maybe this helps.
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>
I have a code I am developing but now I'm Stuck as I'm new to PHP.
When I use simple quotation marks it works but, I think this code is a little ugly and strange, I would like someone to review.
Code:
<?php echo"
<li class='light-blue'>
<a data-toggle='dropdown' href='#' class='dropdown-toggle'>
<img class='nav-user-photo' src='../upload/avatar/$arqDir'>".$_SESSION['img'].">
<span class='user-info'>
<small>Bem Vindo,</small>
echo ".$_SESSION['nome'].";
</span>
<i class='ace-icon fa fa-caret-down'></i>
</a>
<ul class='user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close'>
<li>
<a href='#'>
<i class='ace-icon fa fa-cog'></i>
Cofigurações
</a>
</li>
<li>
<a href='profile.html'>
<i class='ace-icon fa fa-user'></i>
Perfil
</a>
</li>
<li class='divider'></li>
<li>
<a href='logout.php'>
<i class='ace-icon fa fa-power-off'></i>
Sair
</a>
</li>
</ul>
</li>";
?>
As AbraCadaver said, this is one way it could be done:
<li class="light-blue">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
<img class="nav-user-photo" src="../upload/avatar/<?php echo $arqDir . "/" . $_SESSION['img'];?>">
<span class="user-info">
<small>Bem Vindo,</small>
<?php echo $_SESSION['nome']; ?>
</span>
<i class="ace-icon fa fa-caret-down"></i>
</a>
<ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
<li>
<a href="#">
<i class="ace-icon fa fa-cog"></i>
Cofigurações
</a>
</li>
<li>
<a href="profile.html">
<i class="ace-icon fa fa-user"></i>
Perfil
</a>
</li>
<li class="divider"></li>
<li>
<a href="logout.php">
<i class="ace-icon fa fa-power-off"></i>
Sair
</a>
</li>
</ul>
</li>
And another way could be:
<?php
echo '
<li class="light-blue">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
<img class="nav-user-photo" src="../upload/avatar/'. $arqDir . '/' . $_SESSION['img'].'">
<span class="user-info">
<small>Bem Vindo,</small>
'.$_SESSION['nome'].'
</span>
<i class="ace-icon fa fa-caret-down"></i>
</a>
<ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
<li>
<a href="#">
<i class="ace-icon fa fa-cog"></i>
Cofigurações
</a>
</li>
<li>
<a href="profile.html">
<i class="ace-icon fa fa-user"></i>
Perfil
</a>
</li>
<li class="divider"></li>
<li>
<a href="logout.php">
<i class="ace-icon fa fa-power-off"></i>
Sair
</a>
</li>
</ul>
</li>';
In order to remove any confusion, use double quotes in your echo statements and use necessary escaping. For example
echo "<div class=\"boy\"> </div>";
OR
echo"<li class=\"boy\"> </li>";
The class name 'boy' was with double quotes too , so we just escaped it with backlash.
In case when you want to use arrays you just need to close and open quotes when required. For example
echo "The user is: ".$row['user'].":";
The above line will output something like:
The user is: user:
<?php echo"
<li class=\"light-blue\">
<a data-toggle=\"dropdown\" href=\"#\" class=\"dropdown-toggle\">
<img class=\"nav-user-photo\" src=\"../upload/avatar/$arqDir\"".$_SESSION['img'].">
<span class=\"user-info\">
<small>Bem Vindo,</small>
".$_SESSION['nome'].";
</span>
<i class=\"ace-icon fa fa-caret-down\"></i>
</a>
<ul class=\"user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close\">
<li>
<a href=\"#\">
<i class=\"ace-icon fa fa-cog\"></i>
Cofigurações
</a>
</li>
<li>
<a href=\"profile.html\">
<i class=\"ace-icon fa fa-user\"></i>
Perfil
</a>
</li>
<li class=\"divider\"></li>
<li>
<a href=\"logout.php\">
<i class=\"ace-icon fa fa-power-off\"></i>
Sair
</a>
</li>
</ul>
</li>";
?>
I have tried to review and edit code accordingly. I hope you get this.
Three method as I know is:
1. <?php echo $variable; ?>
2.
<?php
echo " $variable ";
?>
3.
<?php
echo <<< LINK
$variable
LINK;
...
?>
I prefered third solutions. In my opinion is the most clear.
In your case should looks like:
echo <<< html
<li class='light-blue'>
<a data-toggle='dropdown' href='#' class='dropdown-toggle'>
<img class='nav-user-photo' src='../upload/avatar/$arqDir'>$_SESSION[img]>
<span class='user-info'>
<small>Bem Vindo,</small>
$_SESSION[nome]
</span>
<i class='ace-icon fa fa-caret-down'></i>
</a>
<ul class='user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close'>
<li>
<a href='#'>
<i class='ace-icon fa fa-cog'></i>
Cofigurações
</a>
</li>
<li>
<a href='profile.html'>
<i class='ace-icon fa fa-user'></i>
Perfil
</a>
</li>
<li class='divider'></li>
<li>
<a href='logout.php'>
<i class='ace-icon fa fa-power-off'></i>
Sair
</a>
</li>
</ul>
</li>
html;
I have to echo a blob image in a carousel but I am not able to use single quotes for the img tag line because of the base64_encode() can someone explain me how to use the double quotes for the img line. Thanks !!!!
Here is my code :
echo "
<div id=\"Carousel$i\" class=\"myCarousel carousel slideCarousel\" data-ride=\"carousel\" data-interval=\"5000\">
<ol class=\"carousel-indicators\">
<li data-target=\"#Carousel$i\" data-slide-to=\"0\" class=\"active\"></li>
<li data-target=\"#Carousel$i\" data-slide-to=\"1\"></li>
<li data-target=\"#Carousel$i\" data-slide-to=\"2\"></li>
<li data-target=\"#Carousel$i\" data-slide-to=\"3\"></li>
</ol>
<div class=\"carousel-inner\" role=\"listbox\">
<div class=\"item active\">";
// HEREEEEE !!!!!!
echo '<img src=\"data:image/jpeg;base64,'.base64_encode($image).'\"/>';
echo "</div>
<div class=\"item\">
<img class=\"slideimage\" src=\"images/diving3.jpg\" alt=\"Chania\">
</div>
<div class=\"item\">
<img class=\"slideimage\" src=\"images/Ambergris-Divers-PADI-Scuba-Course.jpg\" alt=\"Chania\">
</div>
</div>
<a class=\"left carousel-control\" href=\"#Carousel$i\" role=\"button\" data-slide=\"prev\">
<span class=\"glyphicon glyphicon-chevron-left\" aria-hidden=\"true\"></span>
<span class=\"sr-only\">Previous</span>
</a>
<a class=\"right carousel-control\" href=\"#Carousel$i\" role=\"button\" data-slide=\"next\">
<span class=\"glyphicon glyphicon-chevron-right\" aria-hidden=\"true\"></span>
<span class=\"sr-only\">Next</span>
</a>
</div>
";
This should work (stop using double quotes for echo-statements, just to avoid concatenating some strings.
echo '
<div id="Carousel'.$i.'" class="myCarousel carousel slideCarousel" data-ride="carousel" data-interval="5000">
<ol class="carousel-indicators">
<li data-target="#Carousel'.$i.'" data-slide-to="0" class="active"></li>
<li data-target="#Carousel'.$i.'" data-slide-to="1"></li>
<li data-target="#Carousel'.$i.'" data-slide-to="2"></li>
<li data-target="#Carousel'.$i.'" data-slide-to="3"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="data:image/jpeg; base64,'.base64_encode($image).'">
</div>
<div class="item">
<img class="slideimage" src="images/diving3.jpg" alt="Chania">
</div>
<div class="item">
<img class="slideimage" src="images/Ambergris-Divers-PADI-Scuba-Course.jpg" alt="Chania">
</div>
</div>
<a class="left carousel-control" href="#Carousel'.$i.'" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#Carousel'.$i.'" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
';