Here I have a function that gets images from a data table. I need an algorithm that will give me the right pictures depending on what the $page variable is. I have two variables called $max and $min. They show to right pictures on the first page and then it gets messed up. Every page holds a different amount of data I would like to change the $amount variable but I don't know if it have to fixed for the algorithm to work.
function getPhotos() {
$page = 1
$columns = 4;
if (isset($_GET['page'])) {
$page = $_GET['page'];
}
$amount = 2;
$min = $page * $amount - $amount;
$max = $min + $amount;
$query = "SELECT `name` FROM `pictures` ORDER BY `id` DESC LIMIT ".$min.", ".$max."";
$query_run = mysql_query($query);
if (mysql_num_rows($query_run) == 0) {
echo '<h3 class="bad">There are no Photos</h3>';
} else {
$x = 1;
echo '<table id="photoGallery" cellspacing="0" cellpadding="0">';
while ($row = mysql_fetch_assoc($query_run)) {
if ($x == 1) {
echo '<tr>';
}
echo '<td><a href="../Pictures/'.$row['name'].'" target="_blank"><div onclick="click(this)" style="background: url(../Pictures/'.$row['name'].') 50% 50% no-repeat; background-size: 100%; width: 150px; height: 150px; margin: auto;"></div></a></td>';
if ($x == $columns) {
echo '</tr>';
$x = 0;
}
$x++;
}
echo '</table>';
}
}