[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 09-19-2005, 10:24 PM   #1 (permalink)
NamePros Member
 
Join Date: Mar 2005
Posts: 33
53.00 NP$ (Donate)

FreeBaGeL is an unknown quantity at this point


PHP - Changing only center of page with links

Ok, this is the page I'm working on:
http://www.clan-loh.com/dynasty/week...tars2005w1.php

It's set up in php such that a php file builds all the outside stuff, the header at the top of the page, the links on the left side, all the colors, etc. The middle part (the weekly all-stars) are an html report generated by some fantasy football software.

I put that in there with a simple include statement for the html file I am given.

What I would like to do is have the links up above that table (Week : 1 2 3 4 etc) change ONLY that middle file. That way I could have ONE php file called say "all-stars.php" that builds the page, and then 17 html files called say "week1.htm", "week2.htm" etc that it can link to.

As it is now I have 17 php files "all-stars-week1.php" etc and 17 html files to go with them.

I'm pretty sure there's a way to be able to just create one php file that has a switch statement or something of the like and chooses the proper html file depending on what value was passed in from the link, but I'm a bit amiss as to how exactly to get each of the links to pass in the values. Looked around some but it's kind of a difficult thing to search for since it's not a distinct keyword. Any quick help?

Thanks in advance!
FreeBaGeL is offline  
Old 09-19-2005, 11:03 PM   #2 (permalink)
NamePros Regular
 
dkin69's Avatar
 
Join Date: May 2005
Posts: 358
15.75 NP$ (Donate)

dkin69 has a spectacular aura aboutdkin69 has a spectacular aura about


I dont believe there is a way to do this other than frames.
dkin69 is offline  
Old 09-20-2005, 05:58 AM   #3 (permalink)
NamePros Regular
 
moondog's Avatar
 
Join Date: Jun 2004
Posts: 476
3,677.00 NP$ (Donate)

moondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of light


Do it this way:

Have an "main" php file that controls the script execution. In the "main php" script, do includes for all of the header and nav bar stuff.

Then make each week a hyperlink that links to the main php script, but passes the week as a parameter.

Example:

PHP Code:
<a href='script.php?week=1'>1</a> <a href='script.php?week=2'>2</a>
Etc Etc.

Now, you can get the value passed from the hyperlink like this:

PHP Code:
$week = $_GET[week];
From there, you can include the appropriate HTML/PHP file to display the correct week.

Example:
PHP Code:
if($week==1) {include('AllStars2005w1.php');}
elseif(
$week==2) {include('AllStars2005w2.php');}
elseif(
$week==3) {include('AllStars2005w3.php');}
etc etc etc.

Hope this helps.

Happy coding.

-Bob
__________________
The mass purge has begun.
moondog is offline  
Old 09-20-2005, 06:49 AM   #4 (permalink)
NamePros Regular
 
Join Date: Aug 2005
Posts: 214
170.00 NP$ (Donate)

slantednet is on a distinguished road


Example:
PHP Code:
if($week==1) {include('AllStars2005w1.php');}
elseif(
$week==2) {include('AllStars2005w2.php');}
elseif(
$week==3) {include('AllStars2005w3.php');}
Or you can:
PHP Code:
$incpage = "AllStars2005w" . $week . ".php";
include(
$incpage);
To take care of all the weeks...

Mike
Or
__________________
OnlineGames.net
slantednet is offline  
Old 09-20-2005, 07:50 AM   #5 (permalink)
NamePros Regular
 
moondog's Avatar
 
Join Date: Jun 2004
Posts: 476
3,677.00 NP$ (Donate)

moondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of lightmoondog is a glorious beacon of light


Quote:
Originally Posted by slantednet
Or you can:
PHP Code:
$incpage = "AllStars2005w" . $week . ".php";
include(
$incpage);
That works too.

And this is what I love about programming. There is more than one way to skin a cat.


-Bob
__________________
The mass purge has begun.
moondog is offline  
Old 09-21-2005, 05:40 AM   #6 (permalink)
NamePros Member
 
Join Date: Mar 2005
Posts: 33
53.00 NP$ (Donate)

FreeBaGeL is an unknown quantity at this point


Perfect, that's exactly what I was looking for. Thanks fellas.

While I've got you all here. Is there any way for me to kill the "file does not exist error" when they click on the link for a week that isn't up yet. For instance, it's only week 2, so if they click on week 8 it looks for the week 8 file and returns a php error. Can I either A) make this error not show up so they just get a blank page with the links to the weeks or B) give a more user-friendly error, such as "There are no all-stars for this week yet"

Did a search on php error reporting and could only find stuff on php errors, not how to write error reporting of your own.
FreeBaGeL is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 11:35 AM
Tutorial: Simple site management with the use of PHP and the query string(?page=1) deadserious Webmaster Tutorials 8 10-09-2004 01:20 PM
Tutorial: Using PHP require() & include() Dave S Webmaster Tutorials 5 03-22-2004 12:40 AM
Deleted Domain List Site FREE dropscripts For Sale / Advertising Board 12 09-24-2003 07:16 AM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:29 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85