Dynadot โ€” .com Transfer

PHP - Changing only center of page with links

Spaceship Spaceship
Watch

FreeBaGeL

Established Member
Impact
2
Ok, this is the page I'm working on:
http://www.clan-loh.com/dynasty/weeklyAllStars2005w1.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!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
I dont believe there is a way to do this other than frames.
 
0
•••
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:
<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:
$week = $_GET[week];

From there, you can include the appropriate HTML/PHP file to display the correct week.

Example:
PHP:
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
 
0
•••
Example:
PHP:
if($week==1) {include('AllStars2005w1.php');}
elseif($week==2) {include('AllStars2005w2.php');}
elseif($week==3) {include('AllStars2005w3.php');}

Or you can:
PHP:
$incpage = "AllStars2005w" . $week . ".php";
include($incpage);

To take care of all the weeks...

Mike
Or
 
0
•••
slantednet said:
Or you can:
PHP:
$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
 
0
•••
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.
 
0
•••
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back