shadiadiph Posted January 9, 2009 Share Posted January 9, 2009 Hi I have never tried doing this before can someone please give me some tips on how to make this so that if it diplays 5 results per page from the database it will autmatically show links at the bottom of the page to click to page 2 3 etc if there are more than 5 results called from the database. Any tips would be appreciated thanks. <? ini_set ("display_errors", "1"); error_reporting(E_ALL); session_start(); error_reporting(7); require("global/admin_functions.php"); include("results.php"); $sid = $_SESSION['LOGINID']; if($sid!="") { $sql = "select * from tbluserdetails where intAccountID=$sid"; $temps = $DB_site->query($sql); if($row=$DB_site->fetch_array($temps)) { $username = $row["username"]; $email = $row["email"]; $company = $row["company"]; $position = $row["position"]; $lname = $row["lastname"]; $fname = $row["firstname"]; $street = $row["street"]; $city = $row["city"]; $state = $row["state"]; $postal = $row["postal"]; $country = $row["country"]; $password = $row["password"]; $accountid = $row["intAccountID"]; } } else { header ("location: ../../invalid.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>H & M Trading</title> <link rel="stylesheet" type="text/css" href="user.css" /> </head> <body> <div id="wrapper"> <div id="header"> <span class="logo"> </span> </div> <div id="navigation"> <div id="tabs25"> <ul> <li><a href="../index.php" title="Home">Home</a></li> <li><a href="../services.php" title="Services">Services</a></li> <li><a href="../wanted.php" title="Wanted">Wanted</a></li> <li><a href="../products.php" title="Products">Products</a></li> <li><a href="../placead.php" title="Post Ad">Post Ad</a></li> <li><a href="../editad.php" title="Edit Ads">Edit Ads</a></li> <li><a href="../contact.php" title="Contact us">Contact Us</a></li> <li><a href="../logout.php" title="Logout">Logout</a></li> </ul> </div> </div> <div id="content"> <table class="viewads"> <tr><td><h1>MY ADS</h1></td></tr> <tr><td> <table class="viewadscont"> <tr><td class="pix"> </td><td class="titleh" align="center">TITLE</td><td class="category">CATEGORY</td><td class="statush">STATUS</td><td class="action">ACTION</td></tr> <? $sql="select * from tbladvertdetails where intAccountID=$sid order by intAdvertID ASC"; $tempdata=$DB_site->query($sql); $adcount =$DB_site->num_rows($tempdata);{ while($row=$DB_site->fetch_array($tempdata)) { $adid = $row["intAdvertID"]; $title = $row["title"]; $category = $row["category"]; $subcategory = $row["subcategory"]; $status = $row["status"]; $thumbnail1 = $row["thumbnail1"]; $description1 = $row["description1"]; if ($status =="Active") { $classtype = "statusok"; } if ($status =="Pending") { $classtype = "statusx"; } if ($adcount > 0) { if ($thumbnail1 ==true) { echo '<tr><td class="pix"><img src="editpic1.php?adid='.$adid.'" alt="'.$description1.'" /></td> <td class="title"><a href=myadsview.php?adid='.$adid.'>'.$title.'</a></td><td class="category">'.$category.' / '.$subcategory.'</td><td class="'.$classtype.'">'.$status.'</td><td class="action"><a href="myadsview.php?adid='.$adid.'" >EDIT</a> <a href="deletead.php?adid='.$adid.'&action=delete" >DELETE</a></td></tr>'; } } if ($thumbnail1 ==false) { echo '<tr><td class="pix"><img src="../../pix/noimages.png" /></td> <td class="title"><a href=myadsview.php?adid='.$adid.'>'.$title.'</a></td><td class="category">'.$category.' / '.$subcategory.'</td><td class="'.$classtype.'">'.$status.'</td><td class="action"><a href="myadsview.php?adid='.$adid.'" >EDIT</a> <a href="deletead.php?adid='.$adid.'&action=delete" >DELETE</a></td></tr>'; } } if ($adcount == false) { echo '<tr><td class="noads" colspan="5" class="none">You have not yet placed any ads.</td></tr>'; } ?> </table> </td> </tr> </table> </div> <div id="footer"> <table> <tr><td width="720" align="center"> <p>H & M Trading ©2008</p> </td><td width="240"> </td></tr> </table> </div> </div> </body> </html> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/ Share on other sites More sharing options...
.josh Posted January 9, 2009 Share Posted January 9, 2009 http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-732980 Share on other sites More sharing options...
shadiadiph Posted January 9, 2009 Author Share Posted January 9, 2009 thank you just going to check it out now Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-732981 Share on other sites More sharing options...
shadiadiph Posted January 9, 2009 Author Share Posted January 9, 2009 awesome thanks got it working already now i shall spen hours integrating it with my css to get the desired look Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-732997 Share on other sites More sharing options...
.josh Posted January 9, 2009 Share Posted January 9, 2009 awesome. Good luck on that Constant Source of Suffering. Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-732998 Share on other sites More sharing options...
shadiadiph Posted January 9, 2009 Author Share Posted January 9, 2009 My Constant Source of Suffering is over got it integrated easily but you are right css is painful sometimes but you find a good layout just stick with it. As they say if it aint broken dont fix it. That little snippet you sent me to was great just had to remove the db connection parts and it works a treat except for one thing when i am on page two it still tells me i can fo to the first or previous page I am going to play around with it i shall probably break it lol Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-733049 Share on other sites More sharing options...
.josh Posted January 9, 2009 Share Posted January 9, 2009 See that's the great thing about commenting your code; you can easily figure out where to go. If you change the condition to > 2, the << and < links won't show unless you are on page 3++. // if not on page 1, don't show back links if ($currentpage > 2) { // <---- changed from 1 to 2 // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if If you want to show the < (previous) but not the << (first), split it up into two conditions: // if not on page 1, show << (first) link if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; } // end if // if on page 3 or higher, show < (previous) link if ($currentpage > 2) { // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-733071 Share on other sites More sharing options...
shadiadiph Posted January 9, 2009 Author Share Posted January 9, 2009 sorry i didn't actually read this message till I have done it i just changed it all to get it working the first bit i found a work around quite easily but the second part on the second from last value took a bit of thinking. Here is what I ended up with. <? // range of num links to show $range = 3; if ($currentpage ==2) { $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>PREVIOUS</a> "; } if ($currentpage > 2) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>FIRST</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>PREVIOUS</a> "; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } } } if ($currentpage == $totalpages -1) { // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>NEXT</a> "; } else { if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>NEXT</a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>LAST</a> "; } } ?> Now on the second and second from last it only shows previous and next thanks for the help again Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-733081 Share on other sites More sharing options...
shadiadiph Posted January 9, 2009 Author Share Posted January 9, 2009 mm I am having on last problem with the following code it displays the error message No Ads have been placed in this section yet but below that it is still saying NEXT LAST as page selections the end of thre url says .php?currentpage=0 how can I get it so it doesn't display anything do I need to use another if clause? Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-733093 Share on other sites More sharing options...
shadiadiph Posted January 9, 2009 Author Share Posted January 9, 2009 dont worry solved it with this thanks for the help again. <? // range of num links to show $range = 3; if ($currentpage ==2) { $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>PREVIOUS</a> "; } if ($currentpage > 2) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>FIRST</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>PREVIOUS</a> "; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } } } if ($currentpage == $totalpages -1) { // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>NEXT</a> "; } else { if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>NEXT</a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>LAST</a> "; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140094-solved-how-do-i-make-a-results-page-from-this-page/#findComment-733099 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.