 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
06-14-2009, 03:09 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
Pagination
So i know this has been asked a billion times (maybe a trillion but idk), but i tried google, tutorial sites, the search feature here and nothing seems to be working for me i keep getting errors or its not what i need so here i come asking for help again.
I have this to display my data as it is designed to function as a forum but im calling it 'admin notes' in my script.
PHP Code:
<?php
while($rows = mysql_fetch_array($admin_forum_result)) {
$dateformat = "M j, Y";
?>
<tr>
<td class="table_check"><input type="checkbox" class="noborder" /></td>
<td class="table_date"><? echo date($dateformat ,$rows['datetime']); ?></td>
<td class="table_title"><? echo $rows['topic']); ?></td>
<td><? echo $rows['category']); ?></td>
<td><? echo $rows['priority']); ?></td>
<td><? echo $rows['username']); ?></td>
</tr>
<?php } ?>
I want to use pagination to display 5 rows (topics) per page..
My database looks like this:
DB NAME = staff
TABLE NAME = adminforum_question
ROWS = id, topic, message, name, datetime, priority, category
Every tutorial i read kept giving me errors and i got frustrated figuring it out so.
Any help is appreciated.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
06-14-2009, 04:16 AM
|
#2 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
|
You should take a look at this, i know some people who this has helped very much including me, also it's basic + it's a video it's great. Check it out if you don't understand it, let us know but watch it at least 2,3 times.. it takes a while for it to sink in to the head/brain but it will as everything does ;)
PHP Pagination - Part 1
-Cf
__________________
I will be Offline for a while, (Working)..
|
|
|
|
|
The Following 2 Users Say Thank You to codefreek For This Useful Post:
|
|
06-14-2009, 05:16 AM
|
#3 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
Thanks abunch mate! worked perfectly while making me laugh at the same time. Did everything i needed just on part 1 not sure if part 2 does anything more but im going to watch it. thanks.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
06-14-2009, 07:06 AM
|
#4 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
|
np mate ;)
__________________
I will be Offline for a while, (Working)..
|
|
|
|
06-14-2009, 07:28 AM
|
#5 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
Alright read that got a question:
I am trying to make it display all page numbers without doing the "..." things and I cant seem to figure out how I would go about doing that lol.
My code is pretty much exactly the same as his, but his code seems quite messy in my opinion.
Any thoughts?
PHP Code:
<?php // define variables $pageNumber = (isset($_GET["page"]) && is_numeric($_GET["page"])) ? $_GET["page"] : 1; // establish number per page $perPage = 5; // establish padding value $padding = 2; // get start index of results $startIndex = ($pageNumber * $perPage) - $perPage; // get total number of database entries $totalCount = "SELECT COUNT(*) as 'Total' FROM adminforum_question"; $rsCount = mysql_query($totalCount) or die(mysql_error()); $rowCount = mysql_fetch_object($rsCount); // show page listings echo "<div class=\"pagination\">"; // get total number of pages $numOfPages = ceil($rowCount->Total / $perPage); // print link to first page if (($pageNumber != 0) && ($PageNumber != 1) && ($pageNumber != $numOfPages)) { } ?> <span class="pages">Page <?php echo $pageNumber ?> of <?php echo $numOfPages ?> </span> <?php // if our current page, minus padding, greater tthen 1 if (($pageNumber - $padding) > 1) { echo "... "; // set lower limit $lowerLimit = $pageNumber - $padding; // print all padded numbers between lowerlimit and current page for($i = $lowerLimit; $i < $pageNumber; $i++) { echo "<a href=\"index.php?page=".$i."\">".$i."</a> "; } } else { // print all numbers between current page and first page for($i = 2; $i < $pageNumber; $i++) { echo "<a href=\"index.php?page=".$i."\">".$i."</a> "; } } // if were not on first page, or last page, print current page if (($pageNumber != 0) && ($PageNumber != 1) && ($pageNumber != $numOfPages)) { echo "<b> - " . $pageNumber ." - </b>"; } // if current page, plus padding, less then total number of pages if(($pageNumber + $padding) < $numOfPages) { // set upper limit $upperLimit = $pageNumber + $padding; // print all numbers from padding pages above current page for($i = ($upperLimit +1); $i < $pageNumber; $i++) { echo "<a href=\"index.php?page=".$i."\">".$i."</a> "; } echo "... "; } else { // print all page numbers between number of pages and current page for($i = ($pageNumber + 1); $i < $numOfPages; $i++) { echo "<a href=\"index.php?page=".$i."\">".$i."</a> "; } }
echo "</div>"; ?>
Basically I want it to look like this:

__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Last edited by Randy : 06-14-2009 at 07:30 AM.
Reason: added image
|
|
|
06-14-2009, 08:30 AM
|
#6 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
Thanks from me also codefreek i was just about to ask basically the same question as Randy did and now i do not have to wait for an answer.
|
|
|
|
06-14-2009, 09:41 AM
|
#7 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,053
Thanks: 115
|
__________________
|
|
|
|
06-14-2009, 05:48 PM
|
#8 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
|
Randy: just take out the echo "... ";
knight13: i am glad that it helped ;)
__________________
I will be Offline for a while, (Working)..
|
|
|
|
06-14-2009, 07:24 PM
|
#9 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
I figured that but there is a problem because those echo's don't even seem to show up... i just get the 'Page 1 of 3' nothing else works.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
06-14-2009, 09:26 PM
|
#10 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
|
You should take a look at Tanax's Pagination class as well..
__________________
I will be Offline for a while, (Working)..
|
|
|
|
06-15-2009, 01:28 AM
|
#11 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
Watched it for the 5th time and i did my styling while following along instead of after and its working, i guess i was just getting confused with his coding style mixed with mine.
SCREENSHOT OF MY WORK
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Last edited by Randy : 06-15-2009 at 05:00 PM.
|
|
|
06-15-2009, 02:04 PM
|
#12 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
I know this will probably be a stupid question but i have to ask. In the below script where is the $_GET['page'] coming from.
I understand what a ternary operator is but i do not know where the $_GET['page'] is coming from.
PHP Code:
$PageNumber = (isset($_GET['page'])&& is_numeric($_GET['page'])) ? $_GET['paget'] : 1;
This is the code from the video that Codefreek posted.
|
|
|
|
06-15-2009, 03:14 PM
|
#13 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
I may be wrong so dont quote me on it but i believe that is a basic php function where it reads something in the url. i know its a long shot but its all i got.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
06-15-2009, 03:55 PM
|
#14 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
Yea the $_GET[''] gets something out of the url but i do not understand what, because in it is the page but where does the page come from and that is what is confusing me.
|
|
|
|
06-15-2009, 04:59 PM
|
#15 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
nah the $_GET[''] gets something from the url if its not defined by a form, but i believe 'page' is what retrieves a number from the end.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
06-15-2009, 05:05 PM
|
#16 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
From the end of what?
|
|
|
|
06-15-2009, 05:08 PM
|
#17 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
from the url but here is what your looking for:
Your URL is like this correct:
index.php?page=9
by putting $_GET['page'] you are telling it to put page there so change page to whatever you want to be there such as id, number, etc.. and then it reads the number after page=.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
06-16-2009, 05:05 AM
|
#18 (permalink)
|
|
The Frequenter
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 430
Thanks: 30
|
OK i should have looked at the code a little longer thanks!
|
|
|
|
06-16-2009, 05:32 AM
|
#19 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
no problem lol honestly took me about 15 mins reading that line over and over to figure it out, sorry if its not the exact explanation your looking for, im not the best at explaining so I did best I could.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
06-16-2009, 07:07 AM
|
#20 (permalink)
|
|
The Contributor
Join Date: Jun 2009
Location: Seattle, WA
Posts: 79
Thanks: 1
|
Quote:
Originally Posted by knight13
PHP Code:
$PageNumber = (isset($_GET['page'])&& is_numeric($_GET['page'])) ? $_GET['paget'] : 1;
|
Without looking at the code, it seems as though it needs a counter.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|