dropfaith Posted November 13, 2009 Share Posted November 13, 2009 Im using the pagination tutorial by Crayon Violet but im having a hard time editing it to do exactly what i need two issues its for an image gallery so one one page i display thumbnails then you click http://dropfaith.freei.me/galleryimage.php?Id=31&gallery=..headshots.. the thumbnail link like the one above it pulls all images from that gallery but the issue is Id 31 may be above the amount of pages in that gallery because Id is from the table that includes all images spanning multiple gallerys (ie) theres 6 gallerys with 10 images each gallery 4s 3rd image is Id 43 but the way pagination is set up 43 is above the amount of pages in gallery 4 if (isset($_GET['Id']) && is_numeric($_GET['Id'])) { // cast var as int $Id = (int) $_GET['Id']; } else { // default page num $Id = 1; } // end if // if current page is greater than total pages... if ($Id > $totalpages) { // set current page to last page $Id = $totalpages; } // end if // if current page is less than first page... if ($Id < 1) { // set current page to first page $Id = 1; } // end if ----- Second Issue is say the user never entered a website for the photographer or he doesn't have one i don't want that row to display to the user making it look incomplete echo "<tr><td>Photographers Website:<a href=\"". $list['photographersite'] . "\">". $list['photographersite'] . "</a></td></tr>"; <?php // includes include("admin/db_connect.inc.php"); // open database connection $connection = mysql_connect(HOST, DBUSER, PASS) or die('Could not connect !<br />Please contact the site\'s administrator.'); $db = mysql_select_db(DB) or die('Could not connect to database !<br />Please contact the site\'s administrator.'); // find out how many rows are in the table $Gallery = mysql_escape_string(trim(htmlentities($_GET['gallery']))); $sql = "SELECT COUNT(*) FROM images WHERE gallery = '$Gallery'"; $result = mysql_query($sql, $connection) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 1; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['Id']) && is_numeric($_GET['Id'])) { // cast var as int $Id = (int) $_GET['Id']; } else { // default page num $Id = 1; } // end if // if current page is greater than total pages... if ($Id > $totalpages) { // set current page to last page $Id = $totalpages; } // end if // if current page is less than first page... if ($Id < 1) { // set current page to first page $Id = 1; } // end if // the offset of the list, based on current page $offset = ($Id - 1) * $rowsperpage; // get the info from the db $sql = "SELECT * FROM images WHERE gallery = '$Gallery' order by Id asc LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $connection) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo "<table border=\"0\"><tr height=\"450\"><td valign=\"center\" align=\"center\"> "; echo "<img style=\"max-width:400px;\" src=\"". $list['actual'] . "\" /></td></tr> "; echo "<tr><td>Photographer:". $list['photographer'] . "</td></tr>"; echo "<tr><td>Photographers Website:<a href=\"". $list['photographersite'] . "\">". $list['photographersite'] . "</a></td></tr>"; echo "<td><tr><p>". $list['Description'] . "</p></td></tr>"; echo "</td></tr><p>". $list['extra'] . ""; echo "</td></tr></table> "; } // end while echo "<table><tr>"; /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($Id > 1) { // show << link to go back to page 1 echo " <td><a href='{$_SERVER['PHP_SELF']}?Id=1&gallery=$Gallery'>First Pic</a></td> "; // get previous page num $prevpage = $Id - 1; // show < link to go back to 1 page echo " <td><a href='{$_SERVER['PHP_SELF']}?Id=$prevpage&gallery=$Gallery'>Previous </a> </td> "; } // end if // if not on last page, show forward and last page links if ($Id != $totalpages) { // get next page $nextpage = $Id + 1; // echo forward link for next page echo " <td><a href='{$_SERVER['PHP_SELF']}?Id=$nextpage&gallery=$Gallery'>Next </a> </td> "; // echo forward link for lastpage echo " <td><a href='{$_SERVER['PHP_SELF']}?Id=$totalpages&gallery=$Gallery'>Last Pic</a></td></tr></table> "; } // end if /****** end build pagination links ******/ echo "</div>"; echo "</div>"; ?> Quote Link to comment Share on other sites More sharing options...
dropfaith Posted November 13, 2009 Author Share Posted November 13, 2009 Second issue now solved if(empty($list['photographersite'])){ echo " "; } else { echo "<tr><td>Photographers Website:<a href=\"". $list['photographersite'] . "\">". $list['photographersite'] . "</a></td></tr>"; } Quote Link to comment Share on other sites More sharing options...
dropfaith Posted November 14, 2009 Author Share Posted November 14, 2009 bump 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.