This script enables you to create page number links and previous / next links. It is useful when displaying search results or large amount of data. It also allows user to choose how many records to display per page.
By : tebrino
<?php /* This script enables you to create page number links and previous / next links. It is useful when displaying search results or large amount of data. It also allows user to choose how many records to display per page. To use it simply replace MySQL queries with your own. With small changes you can use it with any database server. To use it simply edit the config part and line marked with text "EDIT ME" and that's it. Enjoy. If you have any questions, comments, or if you find any bugs please feel free to contact me: Author: Ilir Fekaj Contact: tebrino@hotmail.com Website / live demo: http://www.freemidi.breezeland.com/page_numbers.php Created: July 01. 2003. Modified: July 02. 2003. Version: 1.0.1 If you like it, use it, you can also give me a credit. */
// config------------------------------------- $host = "localhost"; //your database host $user = "username"; // your database user name $pass = "password"; // your database password $db = "database_name"; // your database name
$filename = "your_file_name.php"; // name of this file $option = array (5, 10, 25, 50, 100, 200); $default = 25; // default number of records per page $action = $_SERVER['PHP_SELF']; // if this doesn't work, enter the filename $query = "SELECT title, url FROM table_name ORDER BY title"; // database query. Enter your query here // end config---------------------------------
$connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect"); mysql_select_db ($db) or die ("Unable to select database $db");
// control query------------------------------ /* this query checks how many records you have in your table. I created this query so we could be able to check if user is trying to append number larger than the number of records to the query string.*/ $off_sql = mysql_query ("$query") or die ("Error in query: $off_sql".mysql_error()); $off_pag = ceil (mysql_num_rows($off_sql) / $nol); //--------------------------------------------
$off = $_GET['offset']; //paranoid if (get_magic_quotes_gpc() == 0) { $off = addslashes ($off); } if (!is_numeric ($off)) { $off = 1; } // this checks if user is trying to put something stupid in query string if ($off > $off_pag) { $off = 1; }
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.