Limited number of database results

Limited number of database results

am 13.12.2006 17:51:47 von Chris Carter

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:








// database information
$host = 'localhost';
$user = 'xxxx';
$password = 'xxxx';
$dbName = 'xxxx';
$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 xxxx 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 "

$showThis

";

$i++;
}

if (num==0)
{
Sorry no results displayed
}
?>



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-tf2 815179.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: Limited number of database results

am 13.12.2006 18:04:22 von Bastien Koert

use the limit clause

$count = 25;

$query="SELECT * FROM xxxx WHERE hello = '$hello' limit $count";

Bastien

>From: Chris Carter
>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:
>
>
>
>
>
>
>
> >
>// database information
> $host = 'localhost';
> $user = 'xxxx';
> $password = 'xxxx';
> $dbName = 'xxxx';
> $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 xxxx 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 "
>
>$showThis
>
>";
>
>$i++;
>}
>
>if (num==0)
>{
>Sorry no results displayed
>}
>?>
>
>
>
>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-tf 2815179.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: Limited number of database results

am 13.12.2006 18:07:32 von Niel Archer

Hi

use a LIMIT clause in your SQL. Something like:

$query="SELECT * FROM xxxx 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: Limited number of database results

am 13.12.2006 23:51:16 von John in Pueblo

Niel Archer wrote:
> Hi
>
> use a LIMIT clause in your SQL. Something like:
>
> $query="SELECT * FROM xxxx 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