Forum Moderators: coopster
How can I modify the script to display 3 rows instead of fixed 2 rows?
Below are the code of the page,
<?php
$link = DB_connect();
$thumb_width = 230;
$rows = 3;
$cols = 3;
// pagination part 1
$TotalToShow = $rows * $cols;
$StartLimit = 0;
if(isset($_GET['Total']))
$TotalToShow = $_GET['Total'];
if(isset($_GET['Start'])) {
if( $_GET['Start'] < 0)
$StartLimit = 0;
else
$StartLimit = $_GET['Start'];
}
if ($TotalToShow == 1) {
if($StartLimit > 0)
$Limit = $StartLimit;
else
$Limit = 1;
} else {
$Limit = $StartLimit . ", " . $TotalToShow;
}
$sql = "SELECT a.*, b.username FROM photos AS a, users AS b WHERE a.userid=b.userid ORDER BY b.username ASC, a.photoid DESC";
if (!$res = mysql_query($sql)) {
$msg = mysql_errno($link) . ": " . mysql_error($link);
} else {
$NumRecords = mysql_num_rows($res);
$sql = $sql." LIMIT $Limit";
$res = mysql_query($sql);
// pagination part 2
$TotalPages = (int)($NumRecords / $TotalToShow);
$NumRemaning = $NumRecords % $TotalToShow;
if($NumRemaning >= "1")
$TotalPages++;
// pagination part 3
$pagination = "";
if($StartLimit != 0) { // Show the previous Link
$No = $StartLimit-$TotalToShow;
$pagination .= '<a href="'.$php_self.'?Total='.$TotalToShow.'&Start='.$No.'">Previous</a> ';
} else {
if ($TotalPages > 1)
$pagination .= "Previous ";
}
// show the page numbers
$NextStartPage = 0;
$pagination .= " ";
for( $x=0; $x < $TotalPages; $x++) {
if( $StartLimit == $NextStartPage) {
if ($TotalPages > 1)
$pagination .= ' '.($x+1).' ';
} else {
$pagination .= ' <a href="'.$php_self.'?Total='.$TotalToShow.'&Start='.$NextStartPage.'">'.($x+1).'</a> ';
}
$NextStartPage = $NextStartPage+$TotalToShow;
}
if(($StartLimit + $TotalToShow) <= ($NumRecords - 1)) { // Show the Next Link
$No = $TotalToShow + $StartLimit;
$pagination .= ' <a href="'.$php_self.'?Total='.$TotalToShow.'&Start='.$No.'">Next</a>';
} else {
if ($TotalPages > 1)
$pagination .= " Next";
}
}
?>
<h1>Photo gallery</h1>
<?
if ($msg <> "") {
echo '<div id="error">';
echo '<h2>System Message</h2>';
echo $msg;
echo '<p><a href="'.$php_self.'">[Back]</a></p>';
echo '</div>';
} else {
echo '<table id="photos">';
if (!mysql_num_rows($res)) {
echo '<tr><td>No photo record found</td></tr>';
} else {
$cols_count = 0;
$rows_count = 0;
while ($row = mysql_fetch_array($res)) {
while (list($key, $val) = each($row))
$$key = $val;
// image related
$real_filepath = IMG_DIR_PHP."/".$filename;
list($width, $height, $type, $attr) = getimagesize($real_filepath);
// do resize here
if ($width > $thumb_width) {
$height = ($thumb_width / $width) * $height;
$width = $thumb_width;
}
$width = round($width, 0);
$height = round($height, 0);
$imgsrc = "get_image.php?id=$photoid&width=$width&height=$height";
$url = "photo.php?id=$photoid";
if (!$modified_date)
$mod_date_text = convertdate($creation_date, false);
else
$mod_date_text = convertdate($modified_date, false);
if ($cols_count == 0)
echo '<tr valign"top">';
$cols_count++; // increment cols count
echo '<td>
<img src="'.$imgsrc.'" alt="'.$filename.'" title="'.$title.'" width="'.$width.'" height="'.$height.'" border="1" />
</td>';
if ($cols_count >= $cols) {
$cols_count = 0;
echo '</tr>';
}
}
}
echo '</table>';
echo $pagination;
}
DB_close();
?>