How do you use "index.php?" to load a new page?

For example, how do you get "" to point to a new page?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lukasz ChmielewskiCommented:
You can use it like this:
   case 1: include("page1.php"); break;
   case 2: include("page2.php"); break;
   default: include("page1.php"); break;

Open in new window

Ray PaseurCommented:
Your script would find this variable, created by the GET method request, using information in the URL.

$_GET["page_number"] == "2"

You would use that variable to decide what new page to load.  You might use include() to load the page.  Or you might use header() to redirect the client browser.

If you're new to PHP programming you might like this book.

Best regards, ~Ray
Hugh McCurdyCommented:
I'm not sure what you mean by "point to a new page."

I can think of 3 definitions.

Link to a new page
Include a new page
Load a new page

And you could me something else.
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

techcwAuthor Commented:
For example, I am trying to load the next page by using "index.php?page_num=2"

Instead of loading the next page, the original index page is loaded instead with the "index.php?page_num=2" part displaying in the browser.

The script I'm using uses the GET method. Do I name the next page something specific?
techcwAuthor Commented:
Here is the script I'm trying to use. Its intent is to paginate without needing a database.

<h1 style="float:left">Pagination Function</h1>
<div style="clear:left;"></div>
<hr />
$num_of_items = 200;
$items_per_page = 9;
$max_links = 10;
	$page_num = $_GET['page_num'];
	$page_num = 1;
<h1>This Is Page: <span style="color:#F00;"># <? echo $page_num; ?></span></h1>
<strong>example:</strong> <br>
<strong>number of items</strong> = <? echo $num_of_items; ?><br>
<strong>number of items per page</strong> = <? echo $items_per_page; ?><br>
<strong>number of links per page</strong> = <? echo $max_links; ?><br>
function pagination_link($id, $page_num){
	return $_SERVER['PHP_SELF'].'?page_num='.$page_num;
function pagination($num_of_items, $items_per_page, $id, $page_num, $max_links){
 	$total_pages = ceil($num_of_items/$items_per_page);
 	if($page_num) {
 		if($page_num >1){ 
 			$prev = ' &nbsp; <a href="'.pagination_link($id, ($page_num -1 )).'">&lt; PREV</a> &nbsp; '; 
 			$first = '<a href="'.$_SERVER['PHP_SELF'].'">&lt;&lt; First Page</a>'; 
	 if($page_num <$total_pages){ 
		$next = ' &nbsp; <a href="'.pagination_link($id, ($page_num+1)).'">NEXT &gt;</a> &nbsp; '; 
		$last = ' &nbsp; <a href="'.pagination_link($id, $total_pages).'">Last Page &gt;&gt;</a> &nbsp; ';
	 echo $first;
	 echo $prev;
	 $loop = 0;
	 if($page_num >= $max_links) {
		$page_counter = ceil($page_num - ($max_links-1));
		$page_counter = 1;
	 if($total_pages < $max_links){
		$max_links = $total_pages;
	 do { 
		if($page_counter == $page_num) {
			echo ' &nbsp; <strong>'.$page_counter.'</strong> &nbsp; '; 
			echo '<a href="'.pagination_link($id, ($page_counter)).'">'.$page_counter.'</a> &nbsp; ';
		$page_counter++; $current_page=($page_counter+1);
	 }while ($max_links > $loop);
	 echo $next;
	 echo $last;

<div align="center">
 pagination($num_of_items, $items_per_page, $id, $page_num, $max_links)

Open in new window

Hugh McCurdyCommented:
OK, still confused by what you mean by load.

1. You want to include the contents of the loaded page within index.php.  You could use this to load a navigation bar, for instance.
2. You don't want index.php to display anything at all.  That is, you want to see (for example) main_catalog.php instead of index.php

In case 1, both Roads_Roads and Ray_Passeur offer good advice (use include).  Ray also noticed that "load" isn't a precise term and suggested you could use header.  Using header is the solution to the 2nd type of load I mentioned.

If you use header, you should output anything first because it won't work.  If you want to use header and you are getting a message like "headers already sent" you can use ob_start() to prevent output until you've processed $_GET.

Finally, I'm still not confident that you understand what we are talking about.  If not, please try to give more information.  (At least choose #1 or #2 or "none of the above" to help us focus on your need.)
Hugh McCurdyCommented:
OK, that makes more sense.  Let me think a bit.
Hugh McCurdyCommented:
I didn't read in great depth but hopefully I got the gist.

Something like this?

Hopefully my selections are in the URL.  If not, just keep expanding the types of shoes you want and eventually page #'s show up.  In any event, is that what you mean about pagination?

What they did is different that what you want.  In your case, if that's what you want for pagination, I'd use header()

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.