Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

How I do page my database results into multi-pages? I need PHP code

user-image
Question ajoutée par Utilisateur supprimé
Date de publication: 2013/04/06
Zaid Rabab'a
par Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.

In order to do this you also need to use the offset value in your SQL Statement, so it would be SELECT * FROM users LIMIT $offset, $perpage Example: SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15 Then to get the links to put on the bottom of your page you would want to get a count of the total data, divide the total by the per page value to figure out how many pages you are going to have. Then set your offset value based on what page the user clicked. Hope that helps! $result = mysql_query("SELECT * FROM users" ); //Note if you have a very large table you probably want to get the count instead of selecting all of the data... $nrResults = mysql_num_rows( $result ); if( $_GET['page'] ) { $page = $_GET['page'] } else { $page = 1; } $per_page = 2; $offset = ($page - 1) * $per_page; //So that page 1 starts at 0, page 2 starts at 2 etc. $result = mysql_query("SELECT * FROM users LIMIT $offset,$per_page"); while( $line = mysql_fetch_array( $result ) ) { //Do whatever you want with each row in here }

Mohamed Magdy
par Mohamed Magdy , System Administrator & Owner , ModServ, LLC.

Instead of mysql_fetch_array() use mysql_fetch_assoc(), it's faster :) Don't forget to secure $_GET.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?