I'm stuck on creating a php pagination script that I want. I've tried loops, etc, and it's not doing the job.. Here's my code for my database that gets what I have now using previous and back links
Code:
<?
Def($start,0);
Def($limit,20);
//Calculate total
$db->open("SELECT count(*) as cnt FROM songlist $where ");
$row = $db->row();
$cnt = $row["cnt"];
//Now grab a section of that
//ORDER BY artist ASC, title ASC
$db->open("SELECT * FROM songlist $where", $limit, $start);
$first = $start+1;
$last = min($cnt,$start+$limit);
$rc = $start;?>
Notice how currently the 1-20 is bold, and if you click on another number say 21-40 and on that it goes bold. That's exactly what I am trying to do.
I already have my SQL statements to. It get's the $rc fine on my page I have, where it shows 1-20 on the rows, but I am unable to figure out how to do the bottom pagination style. I've been trying this for a long time and can't figure it out for the life of me. Any help would greatly be appreciated! Thanks!
I was actually looking to do the range like that at the bottom.. No buttons.. Just the 1-20, etc and if on that page.. say start= 20 then 21-40 would be bold with no <a href="> tag
Also I have a get value called start. So it's like playlist.php?start=0. If start is 0 1-20 songs will show and so forth. I can't seem to figure this pagination out. Can ya help with that? I can't get it to go 1-20 21-40 41-60 and if my start is = $start then that number is bold.
I do want to say I am wanting the links like so:
1-20 21-40 41-60 etc all dependent what is in the database of results, which is what the cnt, etc are already there for.
But honestly although i like the way it does pagination data i did not like the output so what i do is i load the pagination data as normal,
then i grab those vars from the ps pagination script and did my own deal.
Im not saying you have to use ps pagination at all, its just what was in my script and i didnt want to rip it out so i just share the duty with my new way.
Here is the basic process so i hope it helps you. You can also set the range on either side of the current page.
first you do your normal query then you can see where i use the ps pagination to and where i xfer the values to my own deal.
It works perfectly for me.
PHP Code:
$query="did my query here";
$pager = new PS_Pagination($link,$query,$record_per_page,5);
$rs = $pager->paginate();
//############# added for page number display
// grab the values for my own page display code
$maxpg = $pager->max_pages;
$curpg = $pager->page;
$rppg = $pager->rows_per_page;
$off_setpg = $pager->offset;
function pag_links() {
global $curpg, $maxpg;
/****** build the pagination links ******/
// range of num links to show on either side of current page
$range = 5;
// show $range pages on either side of current page. if this includes page
// 1, don't show "First". if this includes last page, don't show "Last"
// show back links |< and < unless at page 1
if ($curpg > 1) {
if ($curpg - $range > 1) { // wouldn't show page 1 in range
well you have the data youll just have to change the out put. If you can give me a few days ill do some testing, im in the middle of a project and my brain power is neck deep in it. But ill be glad to play around with it and get the output changed if you can give me a few days.
If not if anyone can assist would be great, ill check back in a few days and see your status. Im suppose to have this deal done by thursday for my friend.
well you have the data youll just have to change the out put. If you can give me a few days ill do some testing, im in the middle of a project and my brain power is neck deep in it. But ill be glad to play around with it and get the output changed if you can give me a few days.
If not if anyone can assist would be great, ill check back in a few days and see your status. Im suppose to have this deal done by thursday for my friend.
That sounds good because I'm not sure that people understand that this style of pagination:
On there if you click say 21-40 that bolds... it's by the value of net=. On the one I was trying, where I have a previous and next link right now.. and with a ton of results, eh.. the style I want is better.. I use the value start= and it's like $current = "$start"; so it grabs the value and start is +1 so if you're on 0 you're seeing 1-20.. I got all that stuff good.. it's just the pagination for this style is very hard, but I really want it! I have the SQL above and that's the main functions.
Thanks!
Last edited by mfoland; 11-27-2012 at 11:04 PM..
Reason: fixed pagination not showing
I think everyone understands that style of pagination. The pagination would be simple.
PHP Code:
$cnt= //set to value in database $currentpage = $_GET['page']; // Whatever you wanna use. $current = 1; $limit = 20; //Or set to other value, or user defined.
I think everyone understands that style of pagination. The pagination would be simple.
Code:
$cnt= //set to value in database
$currentpage = $_GET['page']; // Whatever you wanna use.
$current = 1;
$limit = 20; //Or set to other value, or user defined.
while($current <= $cnt)
{
$thislast = $current + $limit;
if($thislast > $cnt)
{
$thislast = $cnt;
}
if($current = ((($currentpage - 1) * 20) + 1))
{
echo "<p class = 'paginationBold'>{$current} - {$thislast}</p>";
}
else
echo "<a class = 'paginationLink' href = "insert url">{$current} - {$thislast}</p>";
}
Tried that and I got a blank page.. hmm. I even did the page = and went from there.
EDIT-- The Echo was wrong there.. but After fixing that, it would repeat 1-19 a ton of times. $cnt should be getting the total from the database.
Last edited by mfoland; 11-28-2012 at 02:09 AM..
Reason: Fixed blank page part but new error came about
Didn't think you were just gonna copy paste, but I just revised it in an actual file (was just doing it off the fly but here you go)
PHP Code:
<?php $cnt= 100; //Set to value in database $currentpage = 1; // Whatever you wanna use. Use $_GET so it's dynamic. $current = 1; $limit = 20; //Or set to other value, or user defined.
Didn't think you were just gonna copy paste, but I just revised it in an actual file (was just doing it off the fly but here you go)
Code:
<?php
$cnt= 100; //Set to value in database
$currentpage = 1; // Whatever you wanna use. Use $_GET so it's dynamic.
$current = 1;
$limit = 20; //Or set to other value, or user defined.
while($current <= $cnt)
{
$thislast = $current + $limit;
if($thislast > $cnt)
{
$thislast = $cnt;
}
if($current == ((($currentpage - 1) * 20) + 1))
{
echo '<p class = "paginationBold">'. $current . ' - ' . $thislast . '</p>';
}
else
echo '<a class = "paginationLink" href = "insert url">' . $current . ' - ' . $thislast . '</p>';
$current += $limit; //Added this to update $current. Was missing.
}
?>
I'm new to this.. That's why... On the insert url.. I can do page or current page? = $current, right? I had a pagination that was only previous and next and that it had my start=$next = $current + 20 or - 20
EDIT.. $cnt I'll end up doing $cnt because as you can see in the beginning of the script that's what counts to the total!