I think your method is ok and what you're doing is better than those sites! I think those sites are not dynamic and they add the pictures manually. But it's only one thing that I didn't like about your design, and it's reading everything from the database, and then showing the images in your limit, so, why not using LIMIT clause in your mysql query, like:
$res = mysql_query("SELECT * FROM images LIMIT $from, $length");
Reading everything is gonna be very sluggish when the number of records in your db grow and it's no need that you do it! Even if you need to know the total numbers of your records (I think you need it because you should know how many numbers you should generate), you can use something like:
$res = mysql_query("SELECT count(*) FROM images");
$total_num = mysql_result($res, 0, 0);
Hope that it helped!