<?php
$first = max(0, intval($_GET['first']) - 1);
$last = max($first + 1, intval($_GET['last']) - 1);
$length = $last - $first + 1;
// ---
mysql_connect("localhost","db username","db password") or die(mysql_error());
mysql_select_db("database");
$a = mysql_query("SELECT `images` FROM `table`...