开发者

How to add "View more results" kind of functionality in my PHP based website?

I want to make a website which will recommend users books according to the genre sele开发者_C百科cted by them. I am using PHP, JavaScript and mySQL.

The problem is that there will me almost more than 100 books for a particular genre. I want to display only 10 books at a time and subsequent next 10s to be viewed after clicking a link/button/whatever mentioning -"Next 10 recommendations".

Please tell me what code should I use. Or is there any workaround for it? (what Facebook uses for it (Older posts) link in the bottom of every wall?)


$offset = 0;
if (isset($_GET['offset'])) {
   $offset = abs($_GET['offset']);
}
$where = '';
if (isset($_GET['genre'])) {
   $where = "WHERE genre='".mysql_real_escape_string($_GET['genre'])."'";
}
$sql = "SELECT * FROM books $where LIMIT $offset,10"
// get your data

$offset += 10;
$genre = urlencode($genre);
echo "<a href='?genre=$genre&$offset=$offset'>Get more</a>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜