edawg Posted May 30, 2007 Share Posted May 30, 2007 Im trying to paginate some db results, the problem is, I have categories of pictures with 56 pics in total, now when I try to paginate these results in there own category, rather than get the category pics only to display over a few pages, I get the entire picture db displayed instead. What happens is when I click category "Animals", instead of the 11 pics in that table, I get 6 pics, which is fine as its my Max_Results_Per_Page, but the next page links at the bottom will display all the pictures in the db rather than the ones i need. $display = 6; // rows of results per page if (isset($_GET['np'])) { // if num of pages isset then assign the VAR $num_pages = $_GET['np']; // here its assigned from above. } // Determine where in the database to start returnind results. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Get the users input choice $varCategory = $_GET['cpCategory']; $signs = array("-", "_"); $varCriteria = str_replace($signs, " ", safe_output($_GET['txtSearch'])); // Make the QUERY`s mysql_select_db($database, $connDB); $query_rsResults = "SELECT site_categories.sc_id, site_categories.sc_title, site_categories.sc_keywords, site_categories.sc_description, site_categories.sc_url, site_pictures.sp_id, site_pictures.sc_id, site_pictures.sp_title, site_pictures.sp_description, site_pictures.sp_location, site_pictures.sp_filename_TN, site_pictures.sp_filename, site_pictures.sp_sender, site_pictures.sp_votes FROM site_categories, site_pictures WHERE site_categories.sc_id = site_pictures.sc_id"; // IF Category Search if ($varCategory!="") { $query_rsResults.= " AND (site_categories.sc_url = '$varCategory')"; } // IF Critera Search if ($varCriteria!="") { $query_rsResults.= " AND (site_pictures.sp_description LIKE '%" . $varCriteria . "%' OR site_pictures.sp_title LIKE '%" . $varCriteria . "%' OR site_pictures.sp_ALT LIKE '%" . $varCriteria . "%' OR site_pictures.sp_location LIKE '%" . $varCriteria . "%' OR site_pictures.sp_category LIKE '%" . $varCriteria . "%' OR site_pictures.sp_filename LIKE '%" . $varCriteria . "%' OR site_pictures.sp_filename_TN LIKE '%" . $varCriteria . "%')"; } $query_limit_rsResults = sprintf("%s LIMIT %d, %d", $query_rsResults, $start, $display); $rsResults = mysql_query($query_limit_rsResults, $connDB) or die (mysql_error()); // run the above query $row_rsResults = mysql_fetch_assoc($rsResults); // fetch back as an array of results. $num = mysql_num_rows($rsResults); if ($num > $display) { // more than one page $num_pages = ceil($num_pag/$display); } else { $num_pages = 1; } What am I doing wrong???. Quote Link to comment https://forums.phpfreaks.com/topic/53496-pain-in-the-pagination/ Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 What you need to do is use a limit in your query when on a page. <?php $query = mysql_query("SELECT foo FROM bar LIMIT 0, 6"); // Select the first 6 entries $query = mysql_query("SELECT foo FROM bar LIMIT 7, 6"); // Select 3 entries starting with row seven ?> Just a demo, hope you can slot it into your code Quote Link to comment https://forums.phpfreaks.com/topic/53496-pain-in-the-pagination/#findComment-264565 Share on other sites More sharing options...
OmarHaydoor Posted May 30, 2007 Share Posted May 30, 2007 Read this code: $id = $_GET['id']; if($id == "" || $id <= 0){ $pagee = $_GET['page']; $page_size = 6; if($pagee == ""){ $pagee = 1; } $start = $pagee * $page_size - $page_size; $end = $page_size; $nextpage = $pagee +1; $prepage = $pagee - 1; $re1 = mysql_query("select * from act where showw = '1' order by id desc LIMIT $start,$end"); $counter = 1; print "<table align='center' cellspacing='5'>"; while($ro1 = mysql_fetch_array($re1)){ if($counter == 1){ print "<tr><td><a href='?module=photos&id=".$ro1['id']."'><img src='pic/".$ro1['pic']."' width='110' height='153' class='image'></a></td>"; $counter = 2; }elseif($counter == 2){ print "<td><a href='?module=photos&id=".$ro1['id']."'><img src='pic/".$ro1['pic']."' width='110' height='153' class='image'></a></td>"; $counter = 3; }else{ print "<td><a href='?module=photos&id=".$ro1['id']."'><img src='pic/".$ro1['pic']."' width='110' height='153' class='image'></a></td></tr>"; $counter = 1; } } print "</table>"; $total_re = mysql_query("select * from act where showw = '1'"); $total = mysql_affected_rows(); $divide = $total/$page_size; if($total%$page_size == 0){ $pages = $divide; }else{ $pages = intval($divide) + 1; } print "<br><table width='95%' dir='rtl' align=center> <tr class='text'> <td align='center'>"; for($i=1;$i<=$pages;$i++){ if($pagee == $i){ print "<b>" . $i ."</b>.. "; }else{ print "<a href='?module=photos&page=".$i."' class='text'>".$i."</a> .. "; } } print "</td></tr>"; print "</table>"; }else{ $re1 = mysql_query("select * from act where showw = '1' and id = '".$id."'"); $ro1 = mysql_fetch_array($re1); print "<br><div align='center'><img src='pic/".$ro1['pic']."' width='300' class='image'>"; print "<br><br><a href='JavaScript:history.go(-1)' class='link'>BACK</a></div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53496-pain-in-the-pagination/#findComment-264709 Share on other sites More sharing options...
edawg Posted May 30, 2007 Author Share Posted May 30, 2007 I have a limit line there tho?. $query_limit_rsResults = sprintf( "%s LIMIT %d, %d", $query_rsResults, $start, $display); Quote Link to comment https://forums.phpfreaks.com/topic/53496-pain-in-the-pagination/#findComment-264712 Share on other sites More sharing options...
edawg Posted May 30, 2007 Author Share Posted May 30, 2007 Ive seen tutorials on this subjet, but just cant get them to work on my site?. Quote Link to comment https://forums.phpfreaks.com/topic/53496-pain-in-the-pagination/#findComment-264904 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.