I am trying to break query results into chunks using PHP but can't seem to figure out how to formulate either a query or a loop to break the results into batches of four and surround those four rows with specific HTML elements.
The content is specifically a photography portfolio, where I am just attempting to display photos row by row, but the way I need to style it calls for each row to basically be a separate set of information.
This is the code I'm working with thus far:
<ul class="no-bullet">
<?php
require("connect.php");
$query = "SELECT * FROM dv_photo_work LIMIT 4";
$result = mysql_query($query, $link);
while ($row = mysql_fetch_array($result)) {
print('
<li><img alt="'.$row["img_title"].'" src="'.$row["img_slug"].'></li>');
}
?>
</ul>
I only want four images to be in that list though. And then another four in another list. Can you help me reformulate the loop to make it return four records and then begin a new query of the following four records in another list? There will be approximately 100 records in the database that I will be retrieving this from, so it would have to be able to continue until the entire table is listed.
I imagine this is similar to a pagination process, yet that is another technique that I am unfamiliar with. I'm assuming it's a simple adjustment to the query and mark-up, however I could understand it being something that requires a bit more code creativity than a simple fix.
Many thanks,
Joshie