Jump to content

Help with tables row and columns


superman50

Recommended Posts

I have a small page of php page which grab my images from the SQL tables and display them in a page. The problem now is that the output display only display 3 columns and 2 rows. I want to make it to display 3 rows but it just wont work.

 

How can I modify the script to display 3 rows instead of fixed 2 rows?

 

Below is the php page which Im trying to edit,

 

<?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();

?>

Link to comment
https://forums.phpfreaks.com/topic/149128-help-with-tables-row-and-columns/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.