P
phpgirl
Guest
As the title says, I have images under different IDs in a MySQL database that I would like to display 4 per row and 12 total on a page. So far the page is set up like this:
Except, the above code only works when you want something displayed one per row and ___ per page (deemed $rows_per_page). Since I would like 4 per row, I need help modifying the code to display that accordingly. Any help would be greatly appreciated. Thank you very much for at least taking the time to read through my problem. =)
PHP:
<?php
$hostname = "localhost";
$user = "xyz";
$pass = "xxxxx";
$dbname = "whatever";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbname , $connection) or die ("Cannot select db");
$query = "select * from guestbook order by date desc ";
$result = mysql_query($query) or die(mysql_error());
// dynamic navigation variables
$screen = $_GET['screen'];
$PHP_SELF = $_SERVER['PHP_SELF'];
$rows_per_page=12;
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$query .= "LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die
("Could not execute query : $query." . mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
// display data here..
}
// create the dynamic links
if ($screen > 0) {
$j = $screen - 1;
$url = "$PHP_SELF?screen=$j";
echo "<a href=\"$url\">Prev</a>";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "$PHP_SELF?screen=" . $i;
$j = $i + 1;
echo " | <a href=\"$url\">$j</a> | ";
}
if ($screen < $pages-1) {
$j = $screen + 1;
$url = "$PHP_SELF?screen=$j";
echo "<a href=\"$url\">Next</a>";
}
Except, the above code only works when you want something displayed one per row and ___ per page (deemed $rows_per_page). Since I would like 4 per row, I need help modifying the code to display that accordingly. Any help would be greatly appreciated. Thank you very much for at least taking the time to read through my problem. =)