how to use this ?page=2
Moderator: General Moderators
how to use this ?page=2
i have a picture gallery of ten pages.the names of the pages are as index.php , index2.php , index3.php so on....
every page has a Next and Previous button at the bottom.
when user click on next page it displays the next page like index2.php , index3.php
but
i have seen in some website that the picture gallery which contains more than one pages.
and when user click on next page button the url in the address bar shows like that
http://www.example.com/gallery/index.php?page=2
http://www.example.com/gallery/index.php?page=3
http://www.example.com/gallery/index.php?page=4
and so on....
i also want to use this function.
anyone know how to use this function?
every page has a Next and Previous button at the bottom.
when user click on next page it displays the next page like index2.php , index3.php
but
i have seen in some website that the picture gallery which contains more than one pages.
and when user click on next page button the url in the address bar shows like that
http://www.example.com/gallery/index.php?page=2
http://www.example.com/gallery/index.php?page=3
http://www.example.com/gallery/index.php?page=4
and so on....
i also want to use this function.
anyone know how to use this function?
Re: how to use this ?page=2
That's not a function, it's just a way to think about your project. Instead of having a separate script file for every page, assuming that the pages are quite similar, except for specific content, the idea is to just use one script that checks the URL (the $_GET server array variable) and then inserts appropriate content, depending on that variable.
The general approach is this:
With some words of caution about outputting anything before issuing a header(), another approach is to redirect the browser to a different script file, depending on the URL, but that's another story.
The general approach is this:
Code: Select all
<html>
<head>
...
</head>
<body>
<?php
if(!isset($_GET['page'])) {
$page=1;
} else {
$page=$_GET['page'];
}
...
switch ($page) {
case 1:
echo "This is the content for page one...";
...
break;
case 2:
echo "This is the content for page two...";
...
break;
case 3:
echo "This is the content for page three...";
...
break;
case 4:
echo "This is the content for page four...";
...
break;
...
default:
echo "Invalid page number!";
}
...
$max = 10 // or whatever the highest valid page number may be
$prev = $page <= 1 ? 1 : $page - 1;
$next = $page>= $max ? $max : $page + 1;
echo "<br /> <a href='".$_SERVER['PHP_SELF']."?page=$prev'> < Previous</a> -- ";
echo "<a href='".$_SERVER['PHP_SELF']."?page=$next>Next > </a><br />";
...
?>
Last edited by califdon on Mon Dec 22, 2008 3:41 pm, edited 1 time in total.
Reason: Added the bit about redirection
Reason: Added the bit about redirection
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: how to use this ?page=2
What califdon said is right, just my way of doing it is described here.
Re: how to use this ?page=2
hi califdon.
i simply copy your code and paste it in a php page and test it but it generates an error.
Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\test.php on line 35
i think there is some missing in line no 35 here is code that i have pasted in the page.
i simply copy your code and paste it in a php page and test it but it generates an error.
Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\test.php on line 35
i think there is some missing in line no 35 here is code that i have pasted in the page.
Code: Select all
<html>
<head>
...
</head>
<body>
<?php
if(!isset($_GET['page'])) {
$page=1;
} else {
$page=$_GET['page'];
}
switch ($page) {
case 1:
echo "This is the content for page one...";
break;
case 2:
echo "This is the content for page two...";
break;
case 3:
echo "This is the content for page three...";
break;
case 4:
echo "This is the content for page four...";
break;
default:
echo "Invalid page number!";
}
$max = 10 // or whatever the highest valid page number may be
$prev = $page <= 1 ? 1 : $page - 1;
$next = $page>= $max ? $max : $page + 1;
echo "<br /> <a href='".$_SERVER['PHP_SELF']."?page=$prev'> < Previous</a> -- ";
echo "<a href='".$_SERVER['PHP_SELF']."?page=$next>Next > </a><br />";
?>Re: how to use this ?page=2
Add a semicolon:
Code: Select all
$max = 10; // or whatever the highest valid page number may beRe: how to use this ?page=2
i have tried it it works but there is little bit problem.
i want to echo the index2.php whole page.
so it mean i will paste the whole code of the index2.php in the echo cores??
i have tried to display the image and it works very fine.
i have displayed the picture in page 2
the code is
i want to echo the index2.php whole page.
so it mean i will paste the whole code of the index2.php in the echo cores??
i have tried to display the image and it works very fine.
i have displayed the picture in page 2
the code is
Code: Select all
case 2:
echo "[color=#FF0000]<img src='slides/1.jpg'>[/color]";Re: how to use this ?page=2
OOPS! Thanks, Reviresco. Sorry about that.Reviresco wrote:Add a semicolon:Code: Select all
$max = 10; // or whatever the highest valid page number may be
Basically, whatever you want to happen when "page 2" is selected, that's what you put in the appropriate Case block. If a lot of your page is the same for all pages, then you just do that part once, but wherever something needs to change for different pages, you put that in the Case block. There must be a thousand ways to do it, so I'm not going to write your code for you, but to give you the idea:Tassadduq wrote:i have tried it it works but there is little bit problem.
i want to echo the index2.php whole page.
so it mean i will paste the whole code of the index2.php in the echo cores??
i have tried to display the image and it works very fine.
i have displayed the picture in page 2
the code is
Code: Select all
case 2: echo "[color=#FF0000]<img src='slides/1.jpg'>[/color]";
Code: Select all
<html>
<head>
...
</head>
<body>
<div style='text-align:center; font-size:20pt; color:green; border:2pt solid green;'>
Welcome to my Picture Gallery!
</div>
...
<?php
if(!isset($_GET['page'])) {
$page=1;
} else {
$page=$_GET['page'];
}
...
switch ($page) {
case 1:
echo "This is the content for page one...";
...
break;
case 2:
echo "This is the content for page two...";
...
break;
case 3:
echo "This is the content for page three...";
...
break;
case 4:
echo "This is the content for page four...";
...
break;
...
default:
echo "Invalid page number!";
}
...
$max = 10 // or whatever the highest valid page number may be
$prev = $page <= 1 ? 1 : $page - 1;
$next = $page>= $max ? $max : $page + 1;
echo "<br /> <a href='".$_SERVER['PHP_SELF']."?page=$prev'> < Previous</a> -- ";
echo "<a href='".$_SERVER['PHP_SELF']."?page=$next>Next > </a><br />";
...
?>
<div>Thanks for visiting my galleries! Come back again soon.</div>
</body>
</html>Re: how to use this ?page=2
thank you soooooooo much califdon.
i have done it.
again bundle of thanks.
i have done it.
again bundle of thanks.