942,959 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 732
  • PHP RSS
Jul 29th, 2010
0

Php Dynamic Navigation

Expand Post »
hello, i am building a website using mysql and php on an apache web server. The site has over 100 index pages for differnt parts and content of the site.

one of the problems i am having is i have to write the navigation bars in for each page, and there are more then 100 index's

At present i have two navigation bars a Main and a Side, I want the main to stay the same all the way thru the site, but i would like the Side to change depending on what parent site the user goes to.

currently i have written boths bars into each page which is becomming very tedious, so i would like to create a php include file which would collect the data from the data base and arrange the data on the site.

I have 3 databases. which are as follows

1. nav_main - id.......- main id - primary - auto increment
.................name.....- name of page
.................url_link.- link to page
.................url_img..- link to image which i want to be displayed and linked

2. nav_sub - sid......- sub id - primary - auto increment
..............pid......- parent id - linked with nav_main id
..............name.....- name of page
..............url_link.- link to page
..............url_img..- link to image which i want to be displayed and linked

3. nav_ssub - ssid.....- ssub id - primary - auto increment
..............spid.....- sub parent id - linked with nav_sub sid
..............name.....- name of page
..............url_link.- link to page
..............url_img..- link to image which i want to be displayed and linked

as i have said the database are relationed together for example

¦ssub...........................¦sub......................¦main..........
¦-------------------------------¦-------------------------¦--------------
¦programming.-.ssid:17.spid:4...¦computers.-.sid:4..pid:2.¦books..-..id:2
¦tips........-.ssid:2..spid:1...¦art.......-.sid:1..pid:2.¦books..-..id:2
¦lions.......-.ssid:20.spid:14..¦animals...-.sid:14.pid:3.¦images.-..id:3

above is an example of how i hope i have set it up =)

main stays the same across the top and sub is down the side but ssub would become visable down the side if a sub page is selected.

I hope i have explained this well enough. I am rather new to PHP and MYSQL, If anyone is able to advise me i would be greatful

Thanks in advance

Smiler89
--------------------------------------------------------------------------
Data should be free!
Information is organised data... so
Information should be free!
--------------------------------------------------------------------------
Last edited by smiler89; Jul 29th, 2010 at 9:11 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smiler89 is offline Offline
6 posts
since Jul 2010
Jul 29th, 2010
0
Re: Php Dynamic Navigation
sorry about the format =\ hope it can be read msg me if you would like more information
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smiler89 is offline Offline
6 posts
since Jul 2010
Jul 30th, 2010
1
Re: Php Dynamic Navigation
use this function to write your navigation i think it help you

function buildNav() {
global $_SERVER['PHP_SELF'];
$url = array('index'=>'Home','about'='About','services'=>'Services','portfolio'=>'Portfolio','contact'=>'Contact','support'=>'Support');
$myNav = "<ul>"
foreach ($key=>$value in $url) {
if($_SERVER['PHP_SELF'] == "/$key.php") {
$active = ' class="active"';
}
else {
$active = "";
}
myNav .= "<li$active><a href='/$key.php' title='$value'>$value</a></li>";
}
$myNav .= "</ul>";
return myNav;
}
Reputation Points: 11
Solved Threads: 1
Light Poster
manzarr is offline Offline
39 posts
since Jul 2010
Jul 31st, 2010
0

Query

Click to Expand / Collapse  Quote originally posted by manzarr ...
use this function to write your navigation i think it help you

function buildNav() {
global $_SERVER['PHP_SELF'];
$url = array('index'=>'Home','about'='About','services'=>'Services','portfolio'=>'Portfolio','contact'=>'Contact','support'=>'Support');
$myNav = "<ul>"
foreach ($key=>$value in $url) {
if($_SERVER['PHP_SELF'] == "/$key.php") {
$active = ' class="active"';
}
else {
$active = "";
}
myNav .= "<li$active><a href='/$key.php' title='$value'>$value</a></li>";
}
$myNav .= "</ul>";
return myNav;
}
Thank you for attempting to help me, could you possibly explain what it is you have done so i can get a better understanding, I have spent past day looking at it with no luck =\ Thank you again, i am new too all this.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smiler89 is offline Offline
6 posts
since Jul 2010
Jul 31st, 2010
0
Re: Php Dynamic Navigation
This may be somewhat irrelevant, but if you're new to this, why are you building a site with over 100 pages?
Reputation Points: 10
Solved Threads: 9
Junior Poster in Training
Lsmjudoka is offline Offline
72 posts
since Apr 2009
Jul 31st, 2010
0
Re: Php Dynamic Navigation
Click to Expand / Collapse  Quote originally posted by Lsmjudoka ...
This may be somewhat irrelevant, but if you're new to this, why are you building a site with over 100 pages?
No that is a fair Q, im attempting to learn, i have to start somewhere, been reading books for ever, needed to do something practical. I have attempted it myself, I can use a computer rather well, and i have been useing HTML an CSS for a few years, i thought php would be better.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smiler89 is offline Offline
6 posts
since Jul 2010
Aug 1st, 2010
1
Re: Php Dynamic Navigation
Several years ago, I was writing a cms similar to what your talking about. The problem with calling out to the database to reproduce the navigation menu on each page request is that its a pointless use of server resources and delay. From your administration, create a cache file on every admin update. This way your front end can just call the cache file.
Reputation Points: 11
Solved Threads: 5
Light Poster
EverWebby is offline Offline
46 posts
since Jan 2010
Aug 1st, 2010
0
Re: Php Dynamic Navigation
Click to Expand / Collapse  Quote originally posted by EverWebby ...
Several years ago, I was writing a cms similar to what your talking about. The problem with calling out to the database to reproduce the navigation menu on each page request is that its a pointless use of server resources and delay. From your administration, create a cache file on every admin update. This way your front end can just call the cache file.
I think i may know what you are on about, do you mean so i only have one HTML index page, and all the other pages PHP puts together using includes on request? can php compile HTML? Like i say im new to this am tring to learn tho.

EDIT - Or did you mean create a cache on users computer containing all nav information? that seem like a good idea, but the idea was so i didnt have to write the nav for each index and sub page =\
Last edited by smiler89; Aug 1st, 2010 at 11:03 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smiler89 is offline Offline
6 posts
since Jul 2010
Aug 1st, 2010
0
Re: Php Dynamic Navigation
No I meant to create to output the text to a text file on the server with your administration and then just call that file to bring it into the front-end. The static file include will be alot less resource intense then calling to the database for every page request.
Reputation Points: 11
Solved Threads: 5
Light Poster
EverWebby is offline Offline
46 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Seminar/Workshop
Next Thread in PHP Forum Timeline: Multiple search fields php - Please Help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC