Reputation: 15
I'm not sure how describe my question perfectly or how to begin. But what i can start with is that i'm making a website in PHP for my school and i've never used php before. And what i need is to only change one part of the page i.e the sidebar. or the content, depending if the user clicks i.e school, contact etc.
on my index.php the sidebar shows the news. But in my navbar if you click i.e useful links then the sidebar should change from showing news to showing a couple of links.
And if it is possible, if you then click on one of the links it should only change the content under the navbar and the sidebar should still show the useful links.
<?php
include('include/header.php');
include('include/nav.php');
?>
<div class=content>
<h1>Heading 1</h1>
<p>Text goes here</p>
</div>
<?php include('include/nyheter.php') ?> <--not part of code! this is the sidebar
<?php include('include/footer.php')
For now, i've only got the news to be shown in the index.php using <iframe>
code. but i want to get rid of the <iframe>
and use <div class=sidebar">
or use ID instead of class.
I've search around to find useful information, but most of them says something about AJAX and JQuery, which i don't know what is or even how to use it =(
If you need more information, just ask as spesific as possible, so that i can give the right information =)
EDIT
I've uploaded the entire website to my google drive so that i could share it with you.
as you may see, i've created a bunch of new .php files (most of them was from some other versions that was created in html, and are now converted to PHP.
The link is: https://docs.google.com/folder/d/0BxsqMLXovlRHdmFlOFYzMjlzRHc/edit?usp=sharing
by the way, the website is in Norwegian.
I hope this information can help you to tell me how to solve my question.
remember, i am totally new to PHP and other programming languages other than HTML & CSS.
Upvotes: 0
Views: 3275
Reputation:
Use the php $_GET variable to set which page and navigation you want to use. This is accessed via variables in the url.
For example: www.yoursite.com?page=home&nav=first
You can then include in the php
<?php
$page = $_GET['page'];
$nav = $_GET['nav'];
//set some defaults
if(strlen($page) == 0){ $page = "home"; }
if(strlen($nav) == 0){ $nav = "about"; }
//Then using if statements you can select content and navigation
if($page == "home"){
//print navigation bar with selected link
if($nav == "about"){
//print content for the selected navigation
}
}
?>
Upvotes: 0
Reputation: 2168
<?php
// get current page url
$page = basename($_SERVER["REQUEST_URI"]);
if ($page === "index.php"){
// display news info
}else if($page === "usefulllink.php"){
// display userful links
}
?>
Upvotes: 1
Reputation:
You could use if sentence to change the page content according the url
for example
if($_GET['page'] == "about") {
echo "about page content";
}
elseif($_GET['page'] == "page1") {
echo "page1 content";
}
and so on then you just put links yourpage.com/index.php?page=about into your menu and so on
Upvotes: 1