 |
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: 791
Thanks: 241
|
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
|
|
|
|
|
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: 791
Thanks: 241
|
np mate ;)
|
|
|
|
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, 09:41 AM
|
#6 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
__________________
|
|
|
|
06-14-2009, 05:48 PM
|
#7 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Randy: just take out the echo "... ";
knight13: i am glad that it helped ;)
|
|
|
|
06-14-2009, 07:24 PM
|
#8 (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
|
#9 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
You should take a look at Tanax's Pagination class as well..
|
|
|
|
06-15-2009, 01:28 AM
|
#10 (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, 03:14 PM
|
#11 (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, 04:59 PM
|
#12 (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:08 PM
|
#13 (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:32 AM
|
#14 (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
|
#15 (permalink)
|
|
The Contributor
Join Date: Jun 2009
Location: Seattle, WA
Posts: 76
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 |
Hybrid 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
|
|
|
|