i am using this to collect comments made abt a particular user. i want to display 7 comments on each page and want to enable pagination.
what would be the steps of implementation. sorry. n00b question.
$query = "SELECT msg, user_id, comment_time FROM comments WHERE aid = '$aid' ORDER BY comment_time DESC";
$result = mysql_query($query) or die("ERROR: $query.".mysql_error());
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_object($result)){
$uidval = $row->user_id;
if ($uidval != 0){
$userInfo = $facebook->api_client->fql_query("SELECT name, pic_square_with_logo, profile_url FROM user WHERE uid='".$uidval."'");
// echo '<br>Array Info<br>';
// print_r($userInfo);
// echo '<br><br>';
$nameuser = $userInfo[0]['name'];
$pic = $userInfo[0]['pic_square_with_logo'];
$profile_url = $userInfo[0]['profile_url'];
echo '<img src="'.$pic.'" />';
echo '<a href="'.$profile_url.'">'.$nameuser.'</a>';
echo '<br>';
echo $row->comment_time;
echo '<br>';
echo $row->msg;
echo '<br>';
}
}
}
The solution is best achieved via SQL’s limit/offset clauses. For MySQL, this is achieved via appending
LIMIT [offset] [count]to your query. PostgreSQL uses separateselect ... LIMIT [count] OFFSET [offset]syntax.The idea is you limit the number of results returned to the actual number you want to display. It can yield a huge performance increase if you’re displaying page 1 of 200, with a hundred results per page.
Of course, you need to run a second query – a
select count(*) from ...to determine the number of results in the result set. Divide this by the number of results per page, and you’ve got the number of pages.You will likely want to pass a page parameter in the query string, something like
and then pull the data using a similar method (consider this pseudo code; I know I’m not actually querying properly)