haseebahmed Posted August 13, 2011 Report Share Posted August 13, 2011 (edited) What this Code does is that it helps you achieve Facebok/Twitter Style Pagination. Running Part 1 it loads First 3 ROWS of the MySQL database. Running Part 2 loads the next 3 ROWS of the database. Then you can run Part 2 as many times as you want & it would always load the next 3 ROWS of the database.The Normal Code for this is:- PART1:<?php$query ="SELECT * FROM table ORDER BY id DESC LIMIT 3";$result = mysqli_query($dbc,$query);while($row=mysqli_fetch_array($result)){$row_id=$row['id'];<!-- SOME CODE TO BE EXECUTED -->}?>PART2:<?php$query ="SELECT * FROM table WHERE id>".$row_id." ORDER BY id DESC LIMIT 3";$result = mysqli_query($dbc,$query);while($row=mysqli_fetch_array($result)){$row_id=$row['id'];<!-- SOME CODE TO BE EXECUTED -->}?> Now in my version of the code. I want to order things according to CPC & CPC can be any integer from 10-1. Part 1 of the code is no issue, but how can i make a Part 2 so that every time the next 3 ROWS from the database are listed?Sample Table:ID -- Name -- Country -- CPC01 -- Jhony -- USA -- 1002 -- Tomy -- UAE -- 703 -- Bond -- UK -- 304 -- Ben10 -- USA -- 805 -- Juliana -- UAE -- 106 -- Medina -- UK -- 5 PART 1:<?php$query ="SELECT * FROM table ORDER BY cpc DESC LIMIT 3";$result = mysqli_query($dbc,$query);while($row=mysqli_fetch_array($result)){$row_id=$row['cpc'];<!-- SOME CODE TO BE EXECUTED -->}?> Please help as soon as possible :-) Thanks! Edited August 14, 2011 by haseebahmed Link to comment Share on other sites More sharing options...
astralaaron Posted August 14, 2011 Report Share Posted August 14, 2011 hi you need to pass which page you are on and how many you want to view per page and then do something like this:$page = intval($page);if ($page < 1) $page = 1;$start = (($page - 1) * $per_page);then in your SQL you would add this where you set your order:" ORDER BY `table`.`field` LIMIT $start , $per_page "; Link to comment Share on other sites More sharing options...
haseebahmed Posted August 14, 2011 Author Report Share Posted August 14, 2011 (edited) hi you need to pass which page you are on and how many you want to view per page and then do something like this:$page = intval($page);if ($page < 1) $page = 1;$start = (($page - 1) * $per_page);then in your SQL you would add this where you set your order:" ORDER BY `table`.`field` LIMIT $start , $per_page ";Thanks Alot!! This might be just what i wanted :-D Would tryout & let you know :-)EDIT: Thanks Alot! It worked like a charm :-) Moderator can close the thread now. Edited August 14, 2011 by haseebahmed Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now