我有一些PHP代码,当按下下一个箭头时,它基本上只会获取数据库中的下一个图像。然而,在我的网站上,有时可能会有超过600个用户在线同时点击下一个。有没有办法优化这个PHP代码以使其执行更快?
谢谢!
$nxtImage = mysql_query ("SELECT * FROM images WHERE active=1 and id>$id and section=$section ORDER BY id ASC LIMIT 1") or die (mysql_error());
$nxtrow = mysql_fetch_array($nxtImage);
$nxtnum = mysql_num_rows($nxtImage);
$nid = $nxtrow['id'];
$npicTitle = $nxtrow['img_title'];
$nimgLink = preg_replace("![^a-z0-9]+!i", "-", $npicTitle);
$nimgLink = strtolower($nimgLink);
id
是某种类似于主键的索引,那么它已经被排序了,因此您不需要告诉它要排序任何内容。移除这个ORDER BY id ASC
可能已经增加了此查询的性能。 - HavenardDESC images;
。 - Ja͢ck