FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Limit results/page





Shike
Ok, HERE is a txt file of my script. I was wondering if anyone could help me figure out why it won't limit the results/page the way I want them to?

Any Help would be great.

Thanks

[edit]
I realize that I have the limit set at 2000, but that is so my lists come up right. Smile If you want I can set up my actual search page (which is HERE) so that you can actually see the behavior I'm seeing while working with my actual database.

Again thanks
[/edit]
hexkid
Shike wrote:
Any Help would be great.


The best help you can get is to raise the error reporting of PHP.

Insert these 4 lines at the very beginning of your script:
Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>



You are using undefined variables in your script.


You are using $s here
Code:
// determine if the variable s has been passed to script, if not use 0.  s
// determines which page of results you are on.
if (empty($s)) {
  $s = 0;
} else {
   $s = $_GET['s'];
}
Replace with this
Code:

if (isset($_GET['s'])) {
  $s = (int)$_GET['s'];
  if ($s < 0) {
    $s = 0;
  }
} else {
  $s = 0;
}


You use twice the undefined variable $PHP_SELF. Replace it with $_SERVER['PHP_SELF']
Shike
Ok, I used all of your suggestions. ( added the isset($_GET['limit]?$_GET['limit']:'(sort not set)' to my $limit = $_GET['limit'])

First. When I replaced the &PHP_SELF with $_SERVER['PHP_SELF'] I got errors, so I just named the page (index.php) and that removed the errors, is this ok?

I still get all of the results, but when there are multiple pages, and I click on my link, it "crops" off the proper amount of results from the top, so, if I have 50 results with a limit of 5, page one lists results 1-50, page 2 lists 6-50, page 3 lists 11-50, etc.

Any thoughts? (my Search page is the most "current" version)

[EDIT]
I will do my best to keep the links in the first post the most recent 'version' of the script.

Again thanks for the help.
[/EDIT]
Shike
Shike wrote:
Ok, I used all of your suggestions. ( added the isset($_GET['limit]?$_GET['limit']:'(sort not set)' to my $limit = $_GET['limit'])

First. When I replaced the &PHP_SELF with $_SERVER['PHP_SELF'] I got errors, so I just named the page (index.php) and that removed the errors, is this ok?

I still get all of the results, but when there are multiple pages, and I click on my link, it "crops" off the proper amount of results from the top, so, if I have 50 results with a limit of 5, page one lists results 1-50, page 2 lists 6-50, page 3 lists 11-50, etc.

Any thoughts? (my Search page is the most "current" version)

[EDIT]
I will do my best to keep the links in the first post the most recent 'version' of the script.

Again thanks for the help.
[/EDIT]


Please ignore this page.

All that is happening is when I the 'next page' link it just shifts the numbers ($count++) it doesn't actually limit down the actual results.
hexkid
Shike wrote:
All that is happening is when I the 'next page' link it just shifts the numbers ($count++) it doesn't actually limit down the actual results.


You have a variable $query which you do not use at all.
Code:
// get results of query attaching limiter created by s.  This limit is attached
// to the end of each query when run to handle multiple pages of results.
$query = $search;
if ($testquery != FALSE) {
  $query .= " limit $s,$limit";
  $result = mysql_query($search) or die("Couldn't execute query");
} else {
  $query .= " limit $s,$limit";
  $result = mysql_query($sub_query) or die("Couldn't execute query");
}


In the code above you're building $query with the proper LIMIT instruction but then you use $search or $sub_query anyway in the mysql_query() call.
ammonkc
you could try using a pear library. I've used PEAR:pager and db_pager before. they work fairly well for when I don't need to write my own pager script. I would check it out. it could simplify your limit queries.
Shike
hexkid wrote:
Shike wrote:
All that is happening is when I the 'next page' link it just shifts the numbers ($count++) it doesn't actually limit down the actual results.


You have a variable $query which you do not use at all.
Code:
// get results of query attaching limiter created by s.  This limit is attached
// to the end of each query when run to handle multiple pages of results.
$query = $search;
if ($testquery != FALSE) {
  $query .= " limit $s,$limit";
  $result = mysql_query($search) or die("Couldn't execute query");
} else {
  $query .= " limit $s,$limit";
  $result = mysql_query($sub_query) or die("Couldn't execute query");
}


In the code above you're building $query with the proper LIMIT instruction but then you use $search or $sub_query anyway in the mysql_query() call.


Thanks, I can't believe that I forgot to change those when I changed my variable.

Thanks.

I guess I'll always need a proofreader. Wink
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.