Woodburn2006 Posted April 18, 2009 Share Posted April 18, 2009 i have images in a database and a column in the table is 'orientation'. what i want to do is for the query to get all of the images that are 'l' (landscape) first then get all of the images which are 'p' (portrait) but what i want to do is display them on seperate pages in the images gallery. if you take a look at: http://www.ontherocks.me.uk/index2.php?go=media you will see that the landscape images are directly followed by the portrait images. if i can i would like the portrait images to start on the next page. the page code is: <div id="content_home"> <div id="images_thumbs"> <? $page = $_GET['page'] ? (int) $_GET['page'] : 1; $limit= 9; $query_count = "SELECT count(*) AS rowcount FROM site_images"; $result_count = mysql_query($query_count, $connection); $row_count = mysql_fetch_array($result_count, MYSQL_ASSOC); $totalrows = $row_count['rowcount']; $limitvalue = $page * $limit - ($limit); $query_thumbs = "SELECT * FROM site_images ORDER BY id LIMIT $limitvalue, $limit"; $result_thumbs = mysql_query($query_thumbs) or die("Error: " . mysql_error()); echo"<table width='336' border='0' cellspacing='5' cellpadding='0'> <tr> "; $img_number=0; while ($row_thumbs = mysql_fetch_array($result_thumbs)) { extract($row_thumbs); if($img_number == 3 OR $img_number ==6){ echo " </tr> <tr> <td width='112' valign='middle' align='center'> <A href='$lrg' rel='lightbox[live]' title=''><img id='$id' src='$thumb' height='75px' border='1'></a> </td>"; }else{ echo " <td width='112' valign='middle' align='center'> <A href='$lrg' rel='lightbox[live]' title=''><img id='$id' src='$thumb' height='75px' border='1'></a> </td>"; } $img_number++; } $numofpages = ceil($totalrows / $limit); echo"</td> </tr> <tr> <td colspan='3' class='photos_thumbs' align='center'>"; if($page > 1){ $pageprev = $page - 1; echo" <a href=\"$PHP_SELF?go=media&page=".$pageprev."\"><< Previous Page</a> "; } if($page < $numofpages AND $page > 1){ echo" :: "; } if($page < $numofpages){ $pagenext = $page + 1; echo" <a href=\"$PHP_SELF?go=media&page=".$pagenext."\">Next Page >></a> "; } echo"</td></tr></table>"; ?> </div> </div> is there a way i can do this? thanks Quote Link to comment Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 This is untested so may be off by a page one way or the other but shouldn't be too far wrong I think. <div id="content_home"> <div id="images_thumbs"> <? $page = $_GET['page'] ? (int) $_GET['page'] : 1; $limit= 9; $query_count = "SELECT count(*) AS rowcount FROM site_images"; $result_count = mysql_query($query_count, $connection); $row_count = mysql_fetch_array($result_count, MYSQL_ASSOC); $totalrows = $row_count['rowcount']; $query_count = "SELECT count(*) AS rowcount FROM site_images WHERE orientation = 'l'"; $result_count = mysql_query($query_count, $connection); $row_count = mysql_fetch_array($result_count, MYSQL_ASSOC); $landscaperows = $row_count['rowcount']; // work out if we have a landscape page or a portrait page if ($page * $limit > $landscaperows) { $type = 'p'; $dbpage = $page - (ceil($landscaperows / $limit)); } else { $type = 'l'; $dbpage = $page; } $limitvalue = $dbpage * $limit - ($limit); $query_thumbs = "SELECT * FROM site_images WHERE orientation = '".$type."' ORDER BY id LIMIT $limitvalue, $limit"; $result_thumbs = mysql_query($query_thumbs) or die("Error: " . mysql_error()); echo"<table width='336' border='0' cellspacing='5' cellpadding='0'> <tr> "; $img_number=0; while ($row_thumbs = mysql_fetch_array($result_thumbs)) { extract($row_thumbs); if($img_number == 3 OR $img_number ==6){ echo " </tr> <tr> <td width='112' valign='middle' align='center'> <A href='$lrg' rel='lightbox[live]' title=''><img id='$id' src='$thumb' height='75px' border='1'></a> </td>"; }else{ echo " <td width='112' valign='middle' align='center'> <A href='$lrg' rel='lightbox[live]' title=''><img id='$id' src='$thumb' height='75px' border='1'></a> </td>"; } $img_number++; } $numofpages = ceil($totalrows / $limit); echo"</td> </tr> <tr> <td colspan='3' class='photos_thumbs' align='center'>"; if($page > 1){ $pageprev = $page - 1; echo" <a href=\"$PHP_SELF?go=media&page=".$pageprev."\"><< Previous Page</a> "; } if($page < $numofpages AND $page > 1){ echo" :: "; } if($page < $numofpages){ $pagenext = $page + 1; echo" <a href=\"$PHP_SELF?go=media&page=".$pagenext."\">Next Page >></a> "; } echo"</td></tr></table>"; ?> </div> </div> Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 18, 2009 Author Share Posted April 18, 2009 i get this error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-9, 9' at line 1 ive had a look but cant seem to see the problem Quote Link to comment Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 Try that instead, think I miscalculated. <?php // work out if we have a landscape page or a portrait page if (($page - 1) * $limit > $landscaperows) { $type = 'p'; $dbpage = $page - (ceil($landscaperows / $limit)); } else { $type = 'l'; $dbpage = $page; } Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 19, 2009 Author Share Posted April 19, 2009 superb, thanks alot, works a treat at the mo, will test it ptoperly tomo when i get time Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 20, 2009 Author Share Posted April 20, 2009 ok i have doen some testing, it works fine until i have a full page of landscape images. so if the last page of landscape is full then it will not load any portrait photos. but if there is space for more landscape then it will load portrait images onto next page. and i can assure that there are portrait images on the server check this link for example: http://www.ontherocks.me.uk/index2.php?go=media Quote Link to comment Share on other sites More sharing options...
soak Posted April 20, 2009 Share Posted April 20, 2009 Probably: if ($page * $limit > $landscaperows) { should be: if ($page * $limit >= $landscaperows) { If not I'm pretty sure the issue is going to be on that line. Quote Link to comment Share on other sites More sharing options...
Woodburn2006 Posted April 20, 2009 Author Share Posted April 20, 2009 legendary, cheers mate works a treat Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.