Displaying photos per page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Displaying photos per page?

Post by cturner »

I am wanting to display all photos for each clearing sale. I have the code for displaying all of the clearing sales's information and one photo. I don't know how to display the photos per clearing sale. Can someone please help me get started with this? Thanks in advance.

Code: Select all

require "config.php";
if(!isset($_GET['page'])) {
    $page = 1;
} else {
    $page = $_GET['page'];
}

// Define the number of results per page
$max_results = 1;

// Figure out the limit for the query based
// on the current page number
$from = (($page * $max_results) - $max_results);

// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM `clearingsales` LEFT OUTER JOIN `clearingsales_photos` ON clearingsales.id = clearingsales_photos.parent_id ORDER BY `propertyname` LIMIT $from, $max_results") or die ("Could not query because: " . mysql_error());

while($row = mysql_fetch_array($sql)){
    // Build your formatted results here
	echo '<b><center>'.$row['propertyname'].'</b><br />';
	echo $date.' commencing '.$row['time'].'<br />';
	echo 'A/c '.$row['accountname'].'</center><br />';
	echo $row['comments'].'<br />';
	echo '<div class=title2>'.$row['select1'].'</div> '.$row['txt1'].'<br />';
	echo '<div class=title2>'.$row['select2'].'</div> '.$rpw['txt2'].'<br />';
	echo '<div class=title2>'.$row['select3'].'</div> '.$row['txt3'].'<br />';
	echo '<div class=title2>'.$row['select4'].'</div> '.$row['txt4'].'<br />';
	echo '<div class=title2>'.$row['select5'].'</div> '.$row['txt5'].'<br />';
	echo '<div class=title2>'.$row['select6'].'</div> '.$row['txt6'].'<br />';
	echo '<div class=title2>'.$row['select7'].'</div> '.$row['txt7'].'<br />';
	echo '<div class=title2>'.$row['select8'].'</div> '.$row['txt8'].'<br />';
	echo '<div class=title2>'.$row['select9'].'</div> '.$row['txt9'].'<br />';
	echo '<div class=title2>'.$row['select10'].'</div> '.$row['txt10'].'<br />';
	echo '<div class=title2>'.$row['select11'].'</div> '.$row['txt11'].'<br /><br />';
	echo '<a href=# onClick="popWin(\''.$row['filename'].'.htm\', \'\', \'640\', \'480\')"><img src=http://www.domainname.com/folder1/folder2/'.$row['photos'].' border=0 /></a>';
	echo '<br /><a href="edit_clearing_sale.php?id='.$row['id'].'">EDIT</a> ';
	echo '<a href="delete_clearing_sale.php?id='.$row['id'].'">DELETE</a><br /><br />';
}

if (mysql_affected_rows() == 0) {
	print "No clearing sales to be displayed.";
}


// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) AS Num FROM clearingsales"),0) or die ("Could not query because: " . mysql_error());

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<center>";

if ($page == 1) {
	echo "Previous ";
} else {
	echo "<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

if ($page == $total_pages) {
	echo " Next";
} else {
	echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">Next</a>";
}

echo "</center>";
mysql_close();
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Not exactly sure what you're doing, but if you want to display things in a manner of a certain number per page, with next and previous buttons, it's as simple as assigning id numbers to every element and displaying from a starting number to the ending number.

Use conditions to know whether or not you need to display prev or next buttons.
Post Reply