我将如何为此 MySQL 和 PHP 查询制作分页脚本。
if (isset($_GET['c'])) {
$c = $_GET['c'];
}
$query = mysql_query("SELECT * FROM Categories WHERE category = '$c' ");
WHILE($datarows = mysql_fetch_array($query)):
$id = $datarows['id'];
$category = $datarows['category'];
$code = $datarows['code'];
endwhile;
$query2 = mysql_query("SELECT * FROM Games WHERE category = '$code' ");
WHILE($datarows_cat = mysql_fetch_array($query2)):
$title = $datarows_cat['title'];
$description = $datarows_cat['description'];
$imgurl = $datarows_cat['image_name'];
$category = $datarows_cat['category'];
$views = $datarows_cat['view_count'];
$pagename = $datarows_cat['pagename'];
$featured = $datarows_cat['featured'];
if ($featured =="1") {$f = "<img src='http://my-site.com/images/star.png' width='13px' title='Featured Game' /> Featured"; } else {$f = "";}
if(is_int($views/2)) {
$views = $views / 2;
} else { $views = $views / 2 + .5; }
if (strlen($description) > 95) {
$desc= substr($description,0,95);
$desmod = "$desc...<br/><a href=\"http://my-site.com/$pagename#1\" title=\"$description\">- Read More</a>";
}
else {$desmod = "$description";}
echo "$f - <a href=\"http://my-site.com/$pagename\">$title - $desmod</a><br/>";
endwhile;
例如,当我访问http://my-site.com/categories/Action时,代码会在我的类别表中查找该类别,然后一旦获得该类别的唯一代码,它就会运行另一个查询以查找所有游戏在具有该类别代码的另一个表中。但是,目前,我为一个类别加载了 200 多个游戏,这会导致大量加载时间。
谢谢你的帮助!