Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,379 members, 8,002,413 topics. Date: Thursday, 14 November 2024 at 10:32 AM |
Nairaland Forum / Science/Technology / Programming / Urgent Help Need! Pagination With Php (1049 Views)
Simple Pagination In PHP / GMAIL Style Mailbox Design With PHP Pagination And Sorting / Nairaland : Please Add 1 To The Pagination Counter Not Everyone Is A Programmer (2) (3) (4)
Urgent Help Need! Pagination With Php by Icekelv: 3:28pm On Apr 09, 2015 |
Hi guys; am workin on a project with php n MysQl, And there is a page which I need to display some rows from the database table; the rows inside the table is more than 500, so I want to add a pagination to it that display 50 rows/ when u click (next»), But am finding it difficult to code the pagination part; This was how I selected my rows $select_sql = "SELECT username,age FROM users"; $select_qry = mysql_query($select_sql) or die (mysql_error()); while ($row_select = mysql_fetch_array($select_qry)) { $username = $row_select['username']; $age = $row_select['age'] echo "$username is $age<br/>" } That particular code shows the number of rows which is 500; I want to split it to 50, e.g If a user opens d page, 50 rows will show; Then if the user click (next») or (1») another 50 will show, so on and so forth,! The pagination type can be; (Next» |«Previous) or (1)(2)(3) I will be so glad If u can help! |
Re: Urgent Help Need! Pagination With Php by AkinseteK(m): 4:19pm On Apr 09, 2015 |
I can help you out on that. i have a work i did on pagination that display data like 10 per pages you can call me on 08034089466. |
Re: Urgent Help Need! Pagination With Php by Icekelv: 5:16pm On Apr 09, 2015 |
This aint fair; @akisetek; nairaland is a forum not a business market; I posted dat I needed help; so den y chargin me on phone? If there's anybody here who which to help me; u are free! nd God bless! |
Re: Urgent Help Need! Pagination With Php by abdul01(m): 6:04pm On Apr 09, 2015 |
d secret of pagination is using the SQL LIMIT clause which takes two parameters, the first param is the no of rows to skip and the second is the no of rows to take/return e.g SELECT * FROM table LIMIT 0,10. This means skip 0 rows and take the next 10 rows. Likewise SELECT * FROM table LIMIT 100,20 means skip 100 rows and take the next 20 rows so if i have 500 records(rows) in my table and i want to display 50 records per page, then i would have (500/50 = ) 10 pages. $total_pages = $total_records / $take; // note $take is the no of records we want to display per page so we are going to generate links for the 10 pages and these links will show on all pages to enable us navigate to anypage from anypage. for($i=1; $i<= $total_pages; $i++){ echo "<a href='?page=$i'> page $i </a>"; } just put this below d page or anywhere u want d links to appear. so page 1 would display records 1 to 50 (the query for this would be SELECT * FROM table LIMIT 0,50) page 2 would display records 51 to 100 (the query for this would be SELECT * FROM table LIMIT 50,50) page 3 would display records 101 to 150 (the query for this would be SELECT * FROM table LIMIT 100,50) ... page 10 would display records 451 to 500 (the query for this would be SELECT * FROM table LIMIT 450,50) so now that we have a prototype of the query for each pages, we need to make it dynamic. so if u notice from the above query(s), the only thing that is changing is the 'skip' parameter for LIMIT clause, the 'take' (no of records we wana display per page) is constant. so the next thing is to capture the page that we are currently on (based on d links we generated above) and tell our php script that for this page, skip so so records and take d next 50 records so at the top of d page we should have: $page_no = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1; //since by default the page parameter would not be in the query string (d part after ? in d url, we set it to 1) if($page_no <= 0) $page_no = 1; if($page_no > $total_pages) $page_no = $total_pages; //just some data vaidation check so as not to mess up our query so the next thing is to calculate the dynamic value of the $skip variable: $skip = ($page_no - 1) * $take; so ur query would be "SELECT * FROM table LIMIT $skip, $take"; this would be dynamic depending on the page number we are on. Of course this is just the basics that we need to implement pagination, there are still some more works we need to do such as making sure that the page no passed via d URL isn't outside the boundary of no of possible pages we have, smartly shrinking the generated links in d case where we have large no of records, etc I hope this helps sha, just try and digest it and use it in ur code, if there's any part that isn't clear there let me know, i'm a bit lazy to write a full implementation. cheers. |
Re: Urgent Help Need! Pagination With Php by AkinseteK(m): 7:01pm On Apr 09, 2015 |
Icekelv: Mr man you are not supposed to come here and discuss our transaction here I only ask you to find something for me to help you out like a card and u were saying u will send #200 card.do u think I get my code for free I paid for all this and the time I will use to code your work for u do u think it is #200 worth. I can even help you for free and help you with the code but the way you are talking is not encouraging.once I do it for you for free now u will not thank me and come back to d public that someone have helped you out. |
Re: Urgent Help Need! Pagination With Php by Nobody: 7:52pm On Apr 09, 2015 |
Lol what won't you hear on nl. Op use a pagination library will post a link soon. |
Re: Urgent Help Need! Pagination With Php by Nobody: 7:56pm On Apr 09, 2015 |
Re: Urgent Help Need! Pagination With Php by Guyson(m): 10:18am On Apr 10, 2015 |
Icekelv: My brother, there is no forum in the world where they spoon feed people with codes. If you need help, you have to provide us with what you have done so far on pagination else the best you will get is a link to the tutorial like what was given to you by @pcguru If @akisetek can help you with exactly what you want, I advice that you bargain with him or follow the blog " http://askguyson.com " our next tutorial/free source code will be on pagination |
Re: Urgent Help Need! Pagination With Php by Danyl(m): 10:34pm On Apr 10, 2015 |
Icekelv:can you beep me on whatzap with yr email address I can give you the code for free...I used on my custom-made blog in my signature or drop it here if u can... my phone number is 0 8 0 3 - 0 - 8 - 2 7 9 7 -1 |
Re: Urgent Help Need! Pagination With Php by Nobody: 10:47pm On Apr 10, 2015 |
Arrant nonsense, bros search for "Zebra Pagination", if I am correct the current one uses mysqli, but i got the old version using ordinary mysql (in case you want it). http://stefangabos.ro/php-libraries/zebra-pagination/ |
Re: Urgent Help Need! Pagination With Php by larisoft: 11:22pm On Apr 10, 2015 |
mmm... I always said it...Php doesn't pay. How else do i explain a programmer seeking money online to provide a code snippet? java nd c# all the way man... |
Re: Urgent Help Need! Pagination With Php by Nobody: 2:59pm On Apr 11, 2015 |
First of all i am going to make a long statement so be prepared its going to be harsh but the truth |
Re: Urgent Help Need! Pagination With Php by Nobody: 3:06pm On Apr 11, 2015 |
First i will simply say as a developer i am embarrassed and dissappointed by this page. Being a Developer has nothing to do with codes but finding out things on your own, This is a PAGINATION problem you are dealing with , as in PAGINATION come on. It took me 5 mins to google this out this behaviour of being spoon fed is bad and i can tell you that no company would employ somehow who can't even attempt to give it a try. Sadly i can't mention where I work, but in my work place we deal things that infact na you go start the first topic for Stackoverflow, you need to research and discover and test and do other things. but then again as lairisoft said and i 100% agree with him, its a PHP fault the barrier of entry is too low that anyone can come in. My advise for you is to learn to discover things on your own, also AkinseteK i don't see anything wrong with his statement, I would have told you the same you know why, because I only give or help people who i know have really done alot of the work and are lost, I give free codes to both international framework and local projects. but to be spoon-fed is annonying. please let's keep the pride in programming let's research and find out things on our own and only ask for help when things are too complicated that way we are sharing knowledge and not spoon feeding anyone. As larisoft said let's see you try that with Java in Springs or MVC in .NET you will have to solve your problems yourself. @larisoft mehn I don't like java Web Frameworks geeez too much i edited a Grails project it wasn't bad but the different syntax na turn off. 2 Likes |
Re: Urgent Help Need! Pagination With Php by daddynasa: 3:27pm On Apr 11, 2015 |
document.write('hahahahahahahahaha'); I laugh In javascript. surf d web na, u go see codes plenty concerning pagination. haba. do u really want to learn or u just wnt to copy and paste and go ur way? na wa o. NL programmers. try this in stackoverflow and see the way dem go reply u. |
Re: Urgent Help Need! Pagination With Php by Nobody: 3:40pm On Apr 11, 2015 |
daddynasa: I am in support with your ideas . I am proud to be a copy and paste programmer daddynasa: I am in support with your ideas . I am proud to be a copy and paste programmer |
Re: Urgent Help Need! Pagination With Php by Nobody: 4:45pm On Apr 11, 2015 |
proxy23: I don't call it copy and paste programmer its more of Don't re-invent the wheel just use what someone has done and understand maybe because where we work we need to knw the code before it goes to production server if not our KPI go low. |
(1) (Reply)
Where Can I Learn Programming At A Relatively Cheap Price. / Who Has Noticed This About Swiftng.com? / Sports Equipment
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 72 |