I have some PHP code where once the next arrow is pressed it basically just gets the next image in the data base. However On mywebsite I sometimes can have over 600 users online all clicking next. Is there any way I can opimtize this php code to execute faster?
Thanks!
$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);
The first thing I would do is change the query to this : SELECT `id`, `img_title` FROM images ..., to ensure that you're only grabbing what you need. The next thing I'd do is build a covered index on id, img_title, section, active so that it doesn't have to read off the data page.
Past that, get more hardware, :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With