DeanWhitehouse Posted May 9, 2008 Share Posted May 9, 2008 how can i paginate this require_once 'nav_bar.php'; if (isset($_GET['image_id'])) { if ((int) $_GET['image_id'] > 0) { $imageid = $_GET['image_id']; $sql = "SELECT * FROM hayleyimages WHERE image_id=$imageid"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $imageprofname = $row['image_name']; $imageprofcaption = $row['image_caption']; $imageproflink = $row['image_link']; if(mysql_num_rows($result) > 0) { ?> <table id="portfolio_image"> <tr><th><?php echo "$imageprofname"; ?></th><td><?php echo '<a href="'.$row['image_link'].'" rel="lightbox" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$row['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$row['image_caption']. ' </a>'; ?></td></tr></table> <?php } if (mysql_num_rows($result) < 1) { echo 'This ID does not exist in the database<br>'; echo "<a href=\"index.php\">Return to Image Page</a>"; exit(); } exit(); } else { echo "Unknown Image ID! <br />"; echo "<a href=\"index.php\">Return to Image Page</a>"; exit(); } } //No ID passed to page, display user list: $query = "SELECT image_id, image_name, image_link, image_caption FROM `hayleyimages`"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { ?> <table class="welcome_port"><tr><td>Welcome this is my portfolio.</td></tr></table> <table id="portfolio"> <?php $loop = 3; $loop1 = 3; while($row=mysql_fetch_array($result)){ // Start looping table row if ($loop == 3) { echo "<tr>"; } $toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td> </td>'; $toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td> </td>'; if ($loop == 3) { echo "</tr>"; $loop=0; } } if (substr($toecho, -5) != "</tr>") { $toecho .= "</tr>"; } echo $toecho; echo $toecho1; } ?> </table> <?php if (mysql_num_rows($result) < 1) { echo "No Images To Display"; } mysql_close(); ?> </div> </body> </html> this is the exact piece that needs paginating <?php $loop = 3; $loop1 = 3; while($row=mysql_fetch_array($result)){ // Start looping table row if ($loop == 3) { echo "<tr>"; } $toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td> </td>'; $toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td> </td>'; if ($loop == 3) { echo "</tr>"; $loop=0; } } if (substr($toecho, -5) != "</tr>") { $toecho .= "</tr>"; } echo $toecho; echo $toecho1; } ?> i have tried pagination tutorials, but i can't ever get it to work Link to comment https://forums.phpfreaks.com/topic/104924-pagination-help/ Share on other sites More sharing options...
radar Posted May 9, 2008 Share Posted May 9, 2008 Smarty <3 I've always hated pagination so when I found smarty and the plugin that was created specifically for pagination I jumped at it. Plus smarty will help keep your logic seperate from your html this making programming much easier... Link to comment https://forums.phpfreaks.com/topic/104924-pagination-help/#findComment-537067 Share on other sites More sharing options...
DeanWhitehouse Posted May 9, 2008 Author Share Posted May 9, 2008 does that not have to be used with SmartyPaginate: a class/plugin for data set pagination within the Smarty template environment. Link to comment https://forums.phpfreaks.com/topic/104924-pagination-help/#findComment-537072 Share on other sites More sharing options...
DeanWhitehouse Posted May 9, 2008 Author Share Posted May 9, 2008 any other recomendations? Link to comment https://forums.phpfreaks.com/topic/104924-pagination-help/#findComment-537090 Share on other sites More sharing options...
NorthWestSimulations Posted May 9, 2008 Share Posted May 9, 2008 Well PHP-Freaks has a great Tutorial for Pagitation. But sadly the site's under construction so I cant get to the tutorial. If its not a big thing right now I would simply wait for the tutorial to come back. If its a High priority thing then google is great. Link to comment https://forums.phpfreaks.com/topic/104924-pagination-help/#findComment-537094 Share on other sites More sharing options...
DeanWhitehouse Posted May 9, 2008 Author Share Posted May 9, 2008 i found this code, <?php $max = 2; //amount of articles per page. change to what to want $p = $_GET['p']; if(empty($p)) { $p = 1; } $limits = ($p - 1) * $max; //view the news article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM hayleyimages WHERE image_id = '$id'"); while($r = mysql_fetch_array($sql)) { $title = $r['image_name']; $story = $r['image_caption']; $author = $r['image_link']; echo "<div><p>$title</p><p>$author</p><p>$story</p></div>"; } }else{ //view all the news articles in rows $sql = mysql_query("SELECT * FROM hayleyimages LIMIT ".$limits.",$max") or die(mysql_error()); //the total rows in the table $totalres = mysql_result(mysql_query("SELECT COUNT(image_id) AS tot FROM hayleyimages"),0); //the total number of pages (calculated result), math stuff... $totalpages = ceil($totalres / $max); //the table echo "<table><tr><td>Title</td><td>Author</td></tr><tr>"; while($r = mysql_fetch_array($sql)) { $id = $r['id']; $title = $r['title']; $author = $r['author']; echo "<td><a href='news.php?act=view&id=$id'>$title</a></td><td>$author</td>"; } //close up the table echo "</tr></table>"; for($i = 1; $i <= $totalpages; $i++){ //this is the pagination link echo "<a href='news.php?p=$i'>$i</a>|"; } } ?> now can some explain how to intergrate it into this code, <?php require_once 'nav_bar.php'; if (isset($_GET['image_id'])) { if ((int) $_GET['image_id'] > 0) { $imageid = $_GET['image_id']; $sql = "SELECT * FROM hayleyimages WHERE image_id=$imageid"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $imageprofname = $row['image_name']; $imageprofcaption = $row['image_caption']; $imageproflink = $row['image_link']; if(mysql_num_rows($result) > 0) { ?> <div id="prof_img"> <table id="portfolio_image"> <tr><th><?php echo "$imageprofname"; ?></th></tr><tr><td><?php echo '<a href="'.$row['image_link'].'" rel="lightbox" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$row['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$row['image_caption']. ' </a>'; ?></td></tr><tr><td><a href="portfolio.php">Return To Gallery</a></td></tr></table></div> <?php } if (mysql_num_rows($result) < 1) { echo 'This ID does not exist in the database<br>'; echo "<a href=\"index.php\">Return to Image Page</a>"; exit(); } exit(); } else { echo "Unknown Image ID! <br />"; echo "<a href=\"index.php\">Return to Image Page</a>"; exit(); } } //No ID passed to page, display user list: $query = "SELECT image_id, image_name, image_link, image_caption FROM `hayleyimages`"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { ?> <table class="welcome_port"><tr><td>Welcome this is my portfolio.</td></tr></table> <table id="portfolio"> <?php $loop = 3; $loop1 = 3; while($row=mysql_fetch_array($result)){ // Start looping table row if ($loop == 3) { echo "<tr>"; } $toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td> </td>'; $toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td> </td>'; if ($loop == 3) { echo "</tr>"; $loop=0; } } if (substr($toecho, -5) != "</tr>") { $toecho .= "</tr>"; } echo $toecho; echo $toecho1; } ?> </table> <?php if (mysql_num_rows($result) < 1) { echo "No Images To Display"; } mysql_close(); ?> </div> </body> </html> this bit in particular <?php $loop = 3; $loop1 = 3; while($row=mysql_fetch_array($result)){ // Start looping table row if ($loop == 3) { echo "<tr>"; } $toecho1 .= '<td><a href="?image_id='.$row['image_id'].'">Details</a></td><td> </td>'; $toecho .= '<td><a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="150px" /></a></td><td> </td>'; if ($loop == 3) { echo "</tr>"; $loop=0; } } if (substr($toecho, -5) != "</tr>") { $toecho .= "</tr>"; } echo $toecho; echo $toecho1; } ?> Link to comment https://forums.phpfreaks.com/topic/104924-pagination-help/#findComment-537107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.