Hello, I'm creating a script which firstly fetches columns from database and then save them to an array, then i call them using while loop. What i want is to show page links at bottom like, if the database has 30 items, it should show page 1 - 2 - 3 which means 10 items on single page. I downloaded one script but it didn't work for me. The thing i want to do is like this: ID|NAME|Place 1 | ABC | earth ..... up to 30 ids i save it in $data = mysql_fetch_array($result); then i use this while ($row = $data) { echo $row['id']." ".$row['name']; // and so on... } i want to display links after this thing. i know i can do it using if, elseif commands but thats kinda annoying, i want the links to be dynamic so it saves the headache.. Any solution?? Thanks in advance..
how are you telling php which set to show? say if you have, 3 pages, you can do www.domain.com/index.php?show=2 , which would signify page 2, but then in your code you could do something like '$_GET['show'] * 10 - 9', and then start your array at whatever that value is, so even if you have 100 total id's, and you did show=9, it would show 81-90 If I don't understand your question correctly, please let me know
I wondered this a few weeks ago too http://www.google.com/search?q=php+...s=org.mozilla:en-US:official&client=firefox-a The top 4 results helped greatly.
Take a look at this tutorial: http://www.webrickco.com/article-author-davidc2p-articleid-11-cat-2.html It's the same method crath is presenting. PM me is you need assistance.
@mikey1090, i also tried on google before asking, i tried the first one but it didn't meet my requirement. @webrickco, thank you for sharing link. I will surely contact you if i face any problems. However, i have sort it out using crath's idea, it worked fine. I first counted the database rows and then used loop to create its url and then link them to get command of ['page'] and after that i fetched the $_GET['page'] multiplied it with 10 and it worked fine. I did a few more tweaks to make it work perfect. So far, its working fine, if i get into some trouble, i will share here. Thanks anyways for your replies.
Its basically a logical battle. Once you get your head around it its fine. Quite simple when you look back Just make sure you do some validation on the _GET vars before entering them into your DB queury.
true.^ yea, i try something like if(isset($var)) { // do this } where $var gets the get command. i have created an array $errors = array(); whatever has chances of going wrong, i set $errors = $field etc... therefore, it works quite fine.
basic and simple funda is using limit at your sql query. Simple. *search for script by the key words " pagination php ". ------------------------------------------------- Download Free Ebooks Smart Banking Tips