954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Search pagination problem

Hi I've been trying to make pagination for my search results and I have this problem: The first page displays ok but when the max result per page is achieved like $max_results = 2 and it reached 2 the links for the other pages shows but when clicked on it returns nothing and when I go back to page one nothing shows up either can someone help me out? My code is as follow:
[PHP]
<?php

// Database Connection
include 'ccm_chat/database/database.inc';

// 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 = 10;

// 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 poc_user_data WHERE GENDER LIKE '$gender' AND AGE>='$agemin' AND AGE<='$agemax' AND INTERESTS LIKE '%$interest%' LIMIT $from, $max_results") or die(mysql_error());

while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
echo '


'; echo ''; if(!$row['PICTURE_URL']){ echo 'No Picture Available '; }else{ echo ''.$row['PICTURE_URL'].''; } echo 'User name: '.$row['USER'].''; echo ''; echo ''; echo 'Name: '.$row['NAME'].''; echo ''; echo ''; echo 'Age: '.$row['AGE'].''; echo ''; echo ''; echo 'Gender: '.$row['GENDER'].''; echo ''; echo ''; echo 'Interests: '.$row['INTERESTS'].''; echo ''; echo ''; echo 'Motto: '.$row['MOTTO'].''; echo ''; echo ''; } // Figure out the total number of results in DB: $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM poc_user_data WHERE GENDER LIKE '$gender' AND AGE>='$agemin' AND AGE<='$agemax' AND INTERESTS LIKE '%$interest%'"),0); // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks echo '

Select a Page
';

// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "< ";
}

for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo " ";
}
}

// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "";
}
echo "
";
?>
[/PHP]

StrikeFreedom
Newbie Poster
17 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 
tristan17
Junior Poster in Training
51 posts since Sep 2005
Reputation Points: 10
Solved Threads: 1
 

thank you for this post..
happy birthday to me:D

blanche3
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

excuse me. but is there other simpler codes in search and pagination?
i'm just a novice web developer.. thank you:)

blanche3
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You