[PHP-DB] Limited number of database results
Hi, I have more than 200 rows of data to show to the user. How can I limit it to say 25 rows per page and give an option at the bottom to the user to keep clicking for more till s/he reaches the end of data. my db code is: /tr /thead tbody ?php // database information $host = 'localhost'; $user = ''; $password = ''; $dbName = ''; $hello = $_REQUEST['hello']; mysql_connect(localhost,$user,$password); @mysql_select_db($dbName ) or die( Sorry But There Seems To Be A Problem Connecting To The Database); $query=SELECT * FROM WHERE hello = '$hello'; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i $num) { $showThis=mysql_result($result,$i,showThis); echo tr td$showThis/td /tr; $i++; } if (num==0) { trtdSorry no results displayed/td/tr } ? /tbody/table/div Seems like I am the only one asking questions since past few days. Thanks anyway for your support. I am just about to launch my site. Just after I achieve this. It will be very userfriendly. Thanks in advance. Chris -- View this message in context: http://www.nabble.com/Limited-number-of-database-results-tf2815179.html#a7856535 Sent from the Php - Database mailing list archive at Nabble.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Limited number of database results
use the limit clause $count = 25; $query=SELECT * FROM WHERE hello = '$hello' limit $count; Bastien From: Chris Carter [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Limited number of database results Date: Wed, 13 Dec 2006 08:51:47 -0800 (PST) Hi, I have more than 200 rows of data to show to the user. How can I limit it to say 25 rows per page and give an option at the bottom to the user to keep clicking for more till s/he reaches the end of data. my db code is: /tr /thead tbody ?php // database information $host = 'localhost'; $user = ''; $password = ''; $dbName = ''; $hello = $_REQUEST['hello']; mysql_connect(localhost,$user,$password); @mysql_select_db($dbName ) or die( Sorry But There Seems To Be A Problem Connecting To The Database); $query=SELECT * FROM WHERE hello = '$hello'; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i $num) { $showThis=mysql_result($result,$i,showThis); echo tr td$showThis/td /tr; $i++; } if (num==0) { trtdSorry no results displayed/td/tr } ? /tbody/table/div Seems like I am the only one asking questions since past few days. Thanks anyway for your support. I am just about to launch my site. Just after I achieve this. It will be very userfriendly. Thanks in advance. Chris -- View this message in context: http://www.nabble.com/Limited-number-of-database-results-tf2815179.html#a7856535 Sent from the Php - Database mailing list archive at Nabble.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Download now! Visit http://www.telusmobility.com/msnxbox/ to enter and see how cool it is to get Messenger with you on your cell phone. http://www.telusmobility.com/msnxbox/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Limited number of database results
Hi use a LIMIT clause in your SQL. Something like: $query=SELECT * FROM WHERE hello = '$hello' LIMIT . ($page - 1) * $rows . , $rows; then you only need specify the logic to set the page, row and limitations Niel -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Limited number of database results
Niel Archer wrote: Hi use a LIMIT clause in your SQL. Something like: $query=SELECT * FROM WHERE hello = '$hello' LIMIT . ($page - 1) * $rows . , $rows; then you only need specify the logic to set the page, row and limitations You also typically need to use the mod operand as well to create the 1, 2, 3, pages. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php