I have a page of images populated with information queried with PHP from a MySQL database. I'm attempting to split the query results into pages, and have a select box to allow users to decide how many results per page.
Problem is, I'm stuck! I'm using javascript to post the select box onChange, but don't know how to get that result into the query ($limit
). I also have no idea how to get the page number (represented by $curPage
in the query).
Hope you can fix this and fill in the blanks:
<form name=imgNum action="new_arrivals_img.php" method=POST>
<p>
<select name=ComboName size=1 onChange="imgNum.submit();">
<option value="12" SELECTED>12</option>
<option>16</option>
<option>20</option>
</select>
</p>
</form>
<ul class="new_arrivals_gallery">
<?php
$mysql_link = mysql_connect("localhost", "root", "root");
mysql_select_db("new_arrivals_imgs") or die("Could not select database");
$query = mysql_query("SELECT `imgURL`,`imgTitle` FROM `images` ".
"ORDER BY `imgDate` DESC LIMIT " . $limit * $curPage . ", $limit") or die(mysql_error());
if(!$query) {
echo "Cannot retrieve information from database.";
} else {
while($row = mysql_fetch_assoc($query)) {
echo "<li><a href='new_arrivals_img/".$row['imgURL']."' class='gallery' title='".$row['imgTitle']."'><img src='new_arrivals_img/thumbnails/".$row['imgURL']."'></a></li>";
}
}
?>
</ul>
Also, is it ok that the the form action points to the current page? Or do I have to have two pages?