SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Limiting pagination results
-
Jul 2, 2007, 15:27 #1
- Join Date
- Dec 2006
- Posts
- 430
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Limiting pagination results
Hi Guys,
i am trying to paginate a specific category but am having trouble with my queries, the bottom part of mu pagination returns the correct links the error is here:
PHP Code:$get_id = $_GET['cat_id'];
## browse by category ###########################################################
if ($_GET['cat_id']) {
$_GET['cat_id'] = round(abs(mb_strcut($_GET['cat_id'], 0, 10)));
## cat query ####################################################################
$category_query = "SELECT * FROM `categories` WHERE `id`='$get_id'";
$category_result = mysql_query($category_query) or die (mysql_error());
$category = mysql_fetch_array($category_result) or die (mysql_error());
// a few vars for the cats...///////////////////////////////////////////////////
$cat_id_2 = $category['id'];
$cat_name = $category['name'];
// neat table for category...////////////////////////////////////////////////////
echo '<br /><h4>'.$cat_name.'</h4>';
## display.../////////////////////////////////////////////////////////////////
$cat_dis = "SELECT * FROM `uploaded_files` WHERE `cat_id`='$cat_id_2' ORDER BY `date_added` DESC";
$cat_res = mysql_query($cat_dis) or die (mysql_error());
## Pagination start #############################################################
echo "<center>";
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 5;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM `uploaded_files` WHERE `cat_id`='$cat_id_2' ORDER BY `date_added` DESC $from, $max_results");
## Pagination start #############################################################
Graham
-
Jul 3, 2007, 00:14 #2
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
whats the error Graham?
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jul 3, 2007, 00:24 #3
- Join Date
- Dec 2006
- Posts
- 430
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i knew i forgot to add something lol
my pagination links are fine say 20 results, 5 per page 4 pages:
<<< 1 2 3 4 >>>
but all my results are on the same page instead of on 4.
thanks mate
Graham
-
Jul 3, 2007, 00:27 #4
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am not sure about your situation but its my own simple one please check
PHP Code:mysql_connect("localhost","root","");
mysql_select_db("dotproject");
$perpage = 5;
$start = (isset($_GET['id'])) ? $_GET['id'] : 0;
$TotalRec = mysql_num_rows(mysql_query("SELECT * FROM projects"));
$select = "SELECT * FROM projects LIMIT $start, $perpage";
$result = mysql_query($select) or die(mysql_error());
# Dislay your rows here in the loop
while($rows = mysql_fetch_array($result)){
echo $rows['project_name'] . "=" . $rows['project_start_date'] . "<br>";
}
echo "<br><br>";
if($start == 0){
echo "Previous «";
}else{
echo "<a href=\"./prevnext.php?id=" . ($start - $perpage) . "\">Previous «</a>";
}
echo " ";
if($start == $TotalRec - 1){
echo "Next »";
}else{
echo "<a href=\"./prevnext.php?id=" . ($start + $perpage) . "\">Next »</a>";
}
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Jul 3, 2007, 03:48 #5
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
looks like the limit part is failing. Echo out each query to check it and make sure you are using the right result set from the right query in the output loop.
ie you are using the results from $sql and not $cat_dis ....Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jul 3, 2007, 05:36 #6
- Join Date
- Dec 2006
- Posts
- 430
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi SpikeZ,
i can echo out $cat_dis fine it displays:
PHP Code:SELECT * FROM `uploaded_files` WHERE `cat_id`='1' ORDER BY `date_added` DESC
cheers mate
Graham
-
Jul 3, 2007, 06:13 #7
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
If you are doinf echo $sql it wont as it's a system resource not a string.
PHP Code:$sql_str ="SELECT * FROM `uploaded_files` WHERE `cat_id`='$cat_id_2' ORDER BY `date_added` DESC $from, $max_results";
$sql = mysql_query($sql_str);
echo $sql_str;
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Jul 3, 2007, 11:23 #8
- Join Date
- Dec 2006
- Posts
- 430
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
got it fixed thanks for your help mate
Graham
Bookmarks