Prev/Next Button to scroll through mysql database

//get the current value of "page" in your query string and scrub it to prevent SQL injection if (isset($_GET['page'])) 

    
$currentPage mysql_real_escape_string($_GET['page']); 

else 

    
$currentPage 0
//validate it and calculate values for the Next and Prev links if (ctype_digit($currentPage) && $currentPage >= 0

    
$nextPage $currentPage 1
    
$prevPage $currentPage 1
    
//You probably want to get fancier with this to disable the Prev link if you're at the top 
    
if ($prevPage 0
    { 
        
$prevPage 0
    } 
    
//You probably want to run a query here to see if $nextPage is past the end of your resultset $nextLink "<a href='http://yourwebpage.com?page=$nextPage'>Next</a>"$prevLink "<a href='http://yourwebpage.com?page=$prevPage'>Prev</a>"

echo $nextLink;
echo $prevLink;
//later on in the script when you're creating your HTML output, drop in the link variables  




$sql "SELECT story, post_date FROM memberstories WHERE user_id='$id' ORDER BY post_date DESC LIMIT $page, 1"$result mysql_query(); //as always, check your query for errors! if (!$result

    die(
"Query Error! Query: $sql<br />Error: ".mysql_error()); 
}  

No comments:

Post a Comment