Jump to content

Problem with Search and Pagination


onefitchick

Recommended Posts

Hi everyone,

 

I'm having a problem where if I type a word into my search box, what comes up on the first result page is correct, but then when I click to the second result page, it returns everything that's in my database, and not just the search term anymore.  I'm guessing there is some problem where the search term gets wiped out after the first page.  index.php includes the search box, and searchgym.php is where the results should be and the page navigation.  I would appreciate any help at all as I've been trying to figure this out for days (I'm new to php/mysql and didn't code this myself...).  To see an example online, go to http://www.RateMyFitnessInstructor.com, click on the "find a gym" tab, and type in "world gym".  The first page should have all "world gym", but page 2 and beyond have every gym in the database. 

 

Thanks! 

Link to comment
https://forums.phpfreaks.com/topic/188451-problem-with-search-and-pagination/
Share on other sites

I'm attaching the index file where the search box is located, and searchgym where page 2 does not include the search term, and also ps_pagination file.

 

I think this is all that's involved?

 

Thank you so much!

 

[attachment deleted by admin]

I didn't write it :).  I paid someone to do it.

 

I thinks it's a simple mistake.

He sets the $sql var  to nothing on the pagination page.

here: var $sql = "";

in the class PS_Pagination.

Just delete that line an then try again and see if it works now.

 

class PS_Pagination {
var $php_self;
var $rows_per_page = 10; //Number of records to display per page
var $total_rows = 0; //Total number of rows returned by the query
var $links_per_page = 5; //Number of links to display per page
var $append = ""; //Paremeters to append to pagination links
//==> delete this one: var $sql = "";
var $debug = false;
var $conn = false;
var $page = 1;
var $max_pages = 0;
var $offset = 0;

 

It looks more likely that the page number isn't being passed to/from the class, causing this issue, or it's not being inserted into the query. Don't bother with commenting out the $sql as that will cause issues. That is just the default value for that variable in the class and won't cause any bother

I tried deleting the var $sql = ""; line, but it didn't work.  Thank you Rizla.

 

JAY6390 (or Rizla), how would I check for this: "It looks more likely that the page number isn't being passed to/from the class, causing this issue, or it's not being inserted into the query. "

How about this, the script states $conn but in the function it says $connection ???

 

actual:

function PS_Pagination($connection, $sql, $rows_per_page = 10, $links_per_page = 5, $append = "") {

Try:

function PS_Pagination($conn, $sql, $rows_per_page = 10, $links_per_page = 5, $append = "") {

Thought this was interesting even though I haven't solved the problem...when I click on page 1, the last page is numbered 35 (a reasonable guess at how many pages my search term would output)… and when I click on page 2 or 3, the last page is numbered 98…(which is my entire database).

 

Using View Source:

 

Page 1

 

class="pagination_links">

 

First  <<<span> 1 </span> <span><a href="/searchgym.php?page=2&param1=valu1&param2=value2">2</a></span>  <span><a href="/searchgym.php?page=3&param1=valu1&param2=value2">3</a></span>  <span><a href="/searchgym.php?page=4&param1=valu1&param2=value2">4</a></span> <a href="/searchgym.php?page=2&param1=valu1&param2=value2">>></a> <a href="/searchgym.php?page=35&param1=valu1&param2=value2">Last</a>                                                            </div>

 

Page 3

 

class="pagination_links">

 

<a href="/searchgym.php?page=1&param1=valu1&param2=value2">First</a>  <a href="/searchgym.php?page=2&param1=valu1&param2=value2"><<</a> <span><a href="/searchgym.php?page=1&param1=valu1&param2=value2">1</a></span>  <span><a href="/searchgym.php?page=2&param1=valu1&param2=value2">2</a></span> <span> 3 </span> <span><a href="/searchgym.php?page=4&param1=valu1&param2=value2">4</a></span> <a href="/searchgym.php?page=4&param1=valu1&param2=value2">>></a> <a href="/searchgym.php?page=98&param1=valu1&param2=value2">Last</a>                                                            </div>

 

                                               

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.