Jump to content

SEV3N

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

SEV3N's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [code] //CONNECT AND SELECT DATABASE if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } if($page == "") { $page = 1; } if (preg_match("/[^0-9]/", $page)) { $page = 1; } $max_results = 5; // MAXIMUM RESULTS PER PAGE $from = (($page * $max_results) - $max_results); // YOUR QUERY GOES HERE $query = mysql_query("SELECT * FROM `reg` LIMIT $from, $max_results"); $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `reg`"),0); // end OF YOUR QUERY if ( $total_results == 0 ) { print 'ITEM NOT FOUND'; } // NOTHING FOUND MESSAGE $total_pages = ceil($total_results / $max_results); if ($page > $total_pages && $page <> "1") { print "Page $page not found"; } $first = $from + 1; $i = 0; while($row = mysql_fetch_array($query)){ $last = $first + $i; $i = $i + 1; $name = $row['name']; // PRINT HERE WHAT YOU WANT print "Name: $name<br>"; // END OF PRINTING } // THE ACTUAL PAGINATION STARTS HERE print 'Select a page'; // PREVIOUS if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){     if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } // NEXT if($page < $total_pages){     $next = ($page + 1);     echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next</a>"; } [/code] This should do it. Make sure to keep the same structure for the query. $max_results is the number of items per page. Since you are using the $_GET method the page number is shown in the URL so this code checks if the user input is valid (that's for safety). www.vtop.byethost32.com - is a demo website that I made. Go to "Buy a Developed Web Site to see the code in action. I'm using $_POST there. Hope this helps.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.