Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is bad:</p> <pre><code>$photos = mysql_query("SELECT * FROM photos WHERE album_id='$aid'"); </code></pre> <p>Because it grabs all the fields for the entire album of photos when all you really want is the count. Instead, get the total number of photos in the album like this:</p> <pre><code>$result = mysql_query("SELECT count(1) as total_photos FROM photos WHERE album_id='$aid'"); if ($result === false) { print mysql_error(); exit(1); } $row = mysql_fetch_object($result); $total_photos = $row-&gt;total_photos; mysql_free_result($result); </code></pre> <p>Now you have the count of the total number of photos in the album so that you can set up paging. Let's say as an example that the limit is set to 20 photos per page. So that means that you can list photos 1 - 20, 21 - 40, etc. Create a $page variable (from user input, default 1) that represents the page number you are on and $limit and $offset variables to plug into your query. </p> <pre><code>$limit = 20; $page = $_POST['page'] || 1; // &lt;-- or however you get user input $offset = $limit * ($page - 1); </code></pre> <p>I'll leave the part where you code the list of pages up to you. Next query for the photos based on the variables you created. </p> <pre><code>$result = mysql_query("SELECT * FROM photos WHERE album_id='$aid' ORDER BY pic_id LIMIT $limit OFFSET $offset"); if ($result === false) { print mysql_error(); exit(1); } $photo_num = $offset; while ($row = mysql_fetch_object($result)) { $photo_num++; $pic_id = $row-&gt;pic_id; // get the rest of the variables and do stuff here // like print the photo number for example print "Showing photo $photo_num of $total_photos\n"; } mysql_free_result($result); </code></pre> <p>I'll leave better error handing, doing something with the data, and the rest of the details up to you. But that is the basics. Also I did not check my code for errors so there might be some syntax problems above. To make a single photo per page just make $limit = 1.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload