blyz Posted August 20, 2007 Share Posted August 20, 2007 i have a download section for my site, with about 20 downloads, and i was wondering if their was a script so that it would only show 5, and clicking 'next' button would show the next 5 etc. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/ Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 This is pagination, you should search for it on google, its not that difficult to impliment. You just have to use $_GET to get the page number then set how much you want per page and then just use a loop and ifs. eg <?php $page = $_GET['page']; if(empty($page)) { $page = 1; } $query = //you query $pages = mysql_num_rows($query); $ppp = 5; // post per page $numofpages = ceil($pages/$ppp); if($page == 1) { echo "Prev "; } else { $prev_page = $page-1; echo "<a href=\"{$PHP_SELF}?page={$prev_page}\">Prev </a> | "; } for($i = 1; $i <= $numofpages; $i++) { if($i == $page) { echo "{$i} | "; } else { echo "<a href=\"{$PHP_SELF}?page={$i}\">{$i}</a> | "; } } if($page == $numofpages) { echo "Next "; } else { $next_page = $page+1; echo "<a href=\"{$PHP_SELF}?page={$next_page}\">Next</a> | "; } ?> Hope that helps EDIT: Sorry there were a few typos ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328827 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 ok so where would i put this, and is their a variable i need to give my downloads. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328884 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 i forgot to mention my download section doesnt use mysql, basically i direct them to a page called downloads.php, and this includes a page called applications.php which has 20 little tables each with image and download link. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328900 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 Well I only posted that code to gove you the general idea, I personally do it differently but this will work for a very basic pagination. If your going to use this then all you have to do is get the number of results in your table that you are going to echo thats what the query and mysql_num_rows is for. So you just need a way to find the number of rows in you downloads.php/applications.php I hope that clears it up ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328941 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 Hmm, i dont really understand im a php noob, their are 20 of these on the dowloads page <table width="409" height="115" border="1" bgcolor ="black"> <tr> <td width="70" height="84"><img src="/preview.jpg"></td> <td width="323"><h2> Name. </h2> </td> </tr> <tr><b> <td><img src="/sg.jpg"></td> <td>Size: <a href="downloadurl" target ="_blank">DOWNLOAD NOW!</a></td> </tr> </table></b> so should i give each table a variable ? Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328945 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 can you show the file where you store the stuff and possible some examples of whats in there, just so i can get a better idea. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328947 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 this is the include im using http://software-god.com/appz.php their is going to be 20+ of these tables. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328955 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 so are you storing you data in a file, like csv eg 1,username,password 2,bob,mypass 3,other,so-onso-on etc Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328965 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 im not storing anything atall. all i want it do do isshow a maximum of 5 tables per page, and then clicking 'next' will show the next 5. thats all their is to it, just a bunch of tables. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328968 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 by tables i mean, the html tables on the page i showed u above, not mysql tables. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328971 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 Yea i just realised that Sorry What information will you be inputting into these tables ? (this should be my last question noe ) ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328975 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 their is an example here:http://software-god.com/appz.php just the download name, download link, thumbnail picture, and a small logo. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328976 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 will they be stored in a table, or is it html code you just wanna split up Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328982 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 yes just html code i need to split. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328987 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 well I think the best way would be to put the info into an array $array = array(0 => "some Code", 1 => "some code"); $array_num = count($array); then use a for loop to get it all for($i = 0; $i <= $array_num; $i++) { echo $array[$i]; } or we could just put a few if statements around saying $num = 2; // some random number if($page == $num) { echo "your content"; } ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328994 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 where would i put the 20 html tables? Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-328999 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 Do all the tables have the same structure ? if yes we could use the array if not we would have to use the second option Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-329002 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 yesthey have the same structure Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-329007 Share on other sites More sharing options...
blyz Posted August 20, 2007 Author Share Posted August 20, 2007 the only thing different is description and download link. Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-329010 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 so we just have to put that into an array and we will be sorted <?php $array = array(0 => array(0 => "description", 1 => "link"), 1 => array(0 => "description2", 1 => "link2"), 2 => array(0 => "description3", 1 => "link3")); $array_num = count($array); for($i = 0; $i <= $array_num; $i++) { echo "<table>"; echo "<tr>"; echo "<td>"; echo $array[$i][0]; echo "</td>"; echo "<td>"; echo $array[$i][1]; echo "</td>"; echo "</tr>"; echo "</table>"; } ?> There we go, I think that should be what you wanted, then just add the description and link and change the html. If you need anymore help, you know where to ask. BTW, sorry for not understanding what you meant ;p ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/65813-limited-results-per-page/#findComment-329037 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.