PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Thu Apr 05, 2007 11:50 pm
I haven't been able to work out how to display
Prev , 1,2,3.......34,35,36.Next
Does anyone have any examples that doesn't require the SQL to have a limit set. Could I use an array to store the data?
I guess before we look into the code, a question..
Do I *have* to use Limit on my SQL query to make this work?
Code: Select all
if ( $startrow - $this->pagesize > 0 ) { $prev = $startrow - $this->pagesize; } else { $prev = 0; }
$content .= " <a href = ".$script_name."?".$this->passargs."&fname=".$fname."&searchtext=".$searchtext."&startrow=".$prev.">Prev</a>\n";
for ( $i = 0; $i <= $this->numrows / $this->pagesize; $i++) { // Start Forloop
$startmp = $this->pagesize * $i ;
//if ( $i != 0 ) { $content .= "<b>,</b> "; }
if ( $startmp == $startrow ) {
$fontclass = "medium";
$maxpages = number_format($this->numrows / $this->pagesize, "0");
if ( $i < $maxpages ) {
$next = $this->pagesize * ($i+1);
} else {
$next = $this->pagesize * $i;
}
} else {
$fontclass="";
}
$content .= "<a href = ".$script_name."?".$this->
passargs."&fname=".$fname."&searchtext=".$searchtext."&startrow=" . $startmp." ><font class=".$fontclass.">".$i .", </font></a>";
} // End forloop
$content .= " <a href = ".$script_name."?".$this->passargs."&fname=".$fname."&searchtext=".$searchtext."&startrow=".$next.">Next</a>\n";
tis, Will./
Last edited by
facets on Fri Apr 06, 2007 9:03 am, edited 1 time in total.
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Fri Apr 06, 2007 12:13 am
If you don't use the limit clause, you can retrieve all results into an array, serialize it, and store it into a file for later retrieval. You will lose the simplicity of SQL in retrieve certain results, and each instance of your script will be bloated with all of the data from that table (maybe megabytes if your table is large). It's conventional to get your database data by using LIMIT -- makes your job easier and the data retrieval mechanisms aren't limited to PHP's built-in array functions. Arrays were never intended to hold tabular data.
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Fri Apr 06, 2007 3:49 am
Thanks Aaron.
But..
The link to your site was very handy.
I almost have your Pagination function integrated into my page.
Will./
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Fri Apr 06, 2007 5:01 am
Glad you could make some use of it
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Fri Apr 06, 2007 8:45 am
I think I may be missing something with your pagination code.
When you click on link 12 should it not redisplay with a tweak order? (like the bottom of your website?)
I can't seem to get the current page to set. My URL look like this..
statements.php?searchtext=&fname=All&fname=All&searchtext=&startrow=345
So I have edited the currentPage variable to suit
Code: Select all
$currentPage = (empty($currentPage)) ? '1' : $_GET['searchtext=&fname=All&fname=All&searchtext=&startrow'];
Any ideas why this would not be working?
tia, Will
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Apr 06, 2007 8:49 am
Because PHP will parse the query string.
var_dump($_GET) to see the results.
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Fri Apr 06, 2007 8:55 am
The function expects a page number. Your startrow input ($_GET['startrow']) needs to be converted into a page number, something like
Code: Select all
$resultsPerPage = 20;
$pageNumber = (is_numeric($_GET['startrow']) && $_GET['startrow'] > 0) ? ceil($_GET['startrow'] / $resultsPerPage) : 1;
Then pass that page number to the function along with the total number of results and the results that are being displayed per page.
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Fri Apr 06, 2007 9:02 am
Thank you! That did the trick.
Now, back to getting FreeBSD 6.2 running on my laptop.