...

View Full Version : paging with for loop



gilgalbiblewhee
07-16-2008, 06:02 PM
I'm trying to figure out the formula on how to page a file:

?page=1;
?page=2...
And when page = 1 then what is called $startpage (not to be confused with the paging of the url) would start at 1.
And when page = 2 then what is called $startpage would be 101.
And when page = 3 then what is called $startpage would be 201.

$totalPages=722;
$url_page= $_GET['page'];//grabs the page from the URL. The rest I can't figure out if it's right.
for($thisPage = 1; $thisPage <= $totalPages; $thisPage = $thisPage+100 ){
$startpage = $thisPage;
}
$num_pages = 100;

gilgalbiblewhee
07-16-2008, 07:46 PM
I think I almost figured it out:

/*
$totalPages=722;
$url_page= $_GET['page'];
$num_pages = 100;
for($thisPage = 1; $thisPage <= $totalPages; $thisPage = $thisPage+$num_pages ){
$startpage = $thisPage;
}
*/
$num_pages = 100;//is the number of html pages inserted in a database per minute because online servers can't do all at once
$totalPages=722;//is the total amount of pages of html that exist
$end_url_page= $totalPages/$num_pages;//is LAST page of this file's url. This file will repeat every minute due to the 1 minute rule for online servers with the extension?page=1, ?page=2...
$url_page= $_GET['page'];//is PRESENT page of this file's url.
$startpage = (($url_page - 1 ) * $num_pages) + 1;//is the present html page to be inserted in the database
I tried to be as detailed as possible. If there are any more questions let me know thanks!

dumpfi
07-16-2008, 07:47 PM
$startpage = (isset($_GET['page'])) ?
(((int) $_GET['page']) - 1) * $num_pages + 1 :
1;dumpfi

gilgalbiblewhee
07-16-2008, 07:51 PM
$startpage = (isset($_GET['page'])) ?
(((int) $_GET['page']) - 1) * $num_pages + 1 :
1;dumpfi

That looks neat but I wish I knew what this would do!

Brandoe85
07-16-2008, 08:41 PM
inline conditional...just break it down:


if isset $_GET['page'] then
$startpage = (((int) $_GET['page']) - 1) * $num_pages + 1
else
$startpage = 1

gilgalbiblewhee
07-16-2008, 08:52 PM
inline conditional...just break it down:


if isset $_GET['page'] then
$startpage = (((int) $_GET['page']) - 1) * $num_pages + 1
else
$startpage = 1

What's the difference then between this and

$startpage = (( $_GET['page'] - 1 ) * $num_pages) + 1;?

gilgalbiblewhee
07-17-2008, 05:23 PM
How do you make it so that if the url has no ?page=1 extension then there has to be an assumption that it is 1?
This didn't work:

if($_GET['page']==''){
$url_page = 1;
}else{
$url_page = $_GET['page'];
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum