$php_mysql$ Posted August 4, 2011 Share Posted August 4, 2011 someone guide me on adding page limit please here is my sql function getDetails($ID) { $posts = array(); $sql = "SELECT * FROM `tbl` AS d WHERE d.id = '".$ID."'"; $rs = executeSql($sql); while($row = mysql_fetch_array($rs)) { $posts[] = $row; } return $posts; } and this is how i display it <?php if(!count($adsPost)){ print 'no records'; }else{ foreach($adsPost as $p){ echo "<a href=\"ads_details.php?Category=$catName&ID=".$p['id']."\">".$p['adtitle']."</a>, ".$p['postersname'].", ".date('F jS, Y, g:i a',$p['adtime'])."<br/>"; } } ?> i wish to add 15 results in a page, anyone know how to get it done? i want it like << first page 1 2 3 4 5 [6] 7 last page>> Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/ Share on other sites More sharing options...
Muddy_Funster Posted August 4, 2011 Share Posted August 4, 2011 there are several gudes to this already, try searching the forums. Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1251980 Share on other sites More sharing options...
AyKay47 Posted August 4, 2011 Share Posted August 4, 2011 there are many resources on this topic both here and on the web... many pre-made scripts etc... Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1251987 Share on other sites More sharing options...
$php_mysql$ Posted August 4, 2011 Author Share Posted August 4, 2011 i have seen but i need guidance mebbe you could show me how and where to start? Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1251998 Share on other sites More sharing options...
AyKay47 Posted August 4, 2011 Share Posted August 4, 2011 http://www.google.com/#hl=en&xhr=t&q=php+pagination&cp=9&pf=p&sclient=psy&source=hp&aq=0&aqi=g5&aql=&oq=php+pagin&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=68b3f9ae28a95316&biw=1920&bih=999 Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252001 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2011 Share Posted August 4, 2011 I recommend that you find a php class that does this so that you can pass it your basic query and it provides the methods/properties necessary to add pagination into your existing script. Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252019 Share on other sites More sharing options...
$php_mysql$ Posted August 4, 2011 Author Share Posted August 4, 2011 not helping, understanding nothing at all. can someone show me on my codes above how to get it done? Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252135 Share on other sites More sharing options...
darkfreaks Posted August 5, 2011 Share Posted August 5, 2011 http://www.phpsnaps.com/snaps/view/php-pagination-class/ Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252371 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 OP, instead of all the helpful advice you have been given, i'll attempt to explain pagination. Pagination works based on the offset, this is what actually makes it possible. Heres an explanation of whats going on 1. Grab current page number in the HTTP VAR $currentpage = $_GET['page'] 2. Count the number of rows inside the table you are going to display in the screen $num_rows = mysql_num_rows($query); 3. Create a variable, name it what you want in order to set a limit for the results per page ($rowsperpage= 10) 4. Calculate the total number of pages you are to get, you will need this... $totalpages= ceil($num_rows/$rowsperpage) 5. Now we now how the total number of pages, and the number of results per page to display 6. We need to create an offset, meaning display a certain number of results from starting from this offset based on the current page number $offset = ($currentpage - 1) * $rowsperpage; 7. Now plug this offset into your second query which will actually DISPLAY your content based on the offset, and the total page. The offset tells the code where to start in the query and the total pages tells it where to stop. $sql = mysql_query("SELECT * FROM table_name LIMIT $offset, $rowsperpage"); 8. Create a while loop, display the data. http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252374 Share on other sites More sharing options...
AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 i don't help people that just want the cde written for them, if you want to learn PHP, study and view the provided links..they explain how it works..im not going to write something here that has already been written and explained somewhere else Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252476 Share on other sites More sharing options...
voip03 Posted August 5, 2011 Share Posted August 5, 2011 This is good one http://www.phpfreaks.com/tutorial/basic-pagination phpSensei that g8 Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252507 Share on other sites More sharing options...
AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 This is good one http://www.phpfreaks.com/tutorial/basic-pagination phpSensei that g8 that link was already given.. Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252559 Share on other sites More sharing options...
voip03 Posted August 5, 2011 Share Posted August 5, 2011 O sorry miss line 8 Quote Link to comment https://forums.phpfreaks.com/topic/243836-help-add-pagination/#findComment-1252563 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.