SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Taking the same search query to next page

    Hi there im trying to get my search query to the next page what i have right now is the following:

    Index.php
    Code HTML4Strict:
    <form action="level2.php" method="post">
    the index posts the vars of the form to level2.php
    there I list 5 items of my search result.
    I also have a next 5 link which should give me the next 5 items of my result.
    the problem is that when i click on the link i loose the vars i got form the index. Can anyone give me some suggestions on how to get the next following items without loosing the vars?

  2. #2
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, send the variables to the next page with the url, like

    Code PHP:
    <a href="<?=$_SERVER['PHP_SELF']?>?var1=<?=$var1?>&var2=<?=$var2?>">go to the next page</a>

    At the top of level2.php, fetch the results with request.

    Code PHP:
    if (isset($_REQUEST['var1']) && $_REQUEST['var1'] != '')) {
      $var1 = $_REQUEST['var1'];
    }

  3. #3
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    It worked

    Could you tell me what the difference is between $_Request and $_Post?

  4. #4
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_REQUEST contains GET, POST, and COOKIE variables.

  5. #5
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be using GET.

  6. #6
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually I spoke about request since he was sending his first form data as post, and for the second page, it was getting get ...

  7. #7
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll notice that most search interfaces use GET. People like to use the back button with searches. As mentioned, pass the variables in the url by appending them to each link. If you are doing pagination, it is also advisable to carry over the total number of records as well, so that you aren't doing a "COUNT" query each time to do the calculations.

    I have seen it suggested to use a session variable to carry over variables. The only problem with that is that if someone wants to bookmark the search, they can't.

  8. #8
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hammer65 View Post
    If you are doing pagination, it is also advisable to carry over the total number of records as well, so that you aren't doing a "COUNT" query each time to do the calculations.
    There is no need to do a COUNT(*) query to do pagination... Nor a need to pass a record of the total number of pages.

  9. #9
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to know the total number of records for the given criteria (WHERE clause), in order to know how many pages of links you can have and where it ends (last page). Most pagination scripts I have seen do a count or calc_found_rows query, once and then cache or pass the count there after. If you have a different way, by all means demonstrate it. Otherwise your response isn't very helpful to the OP.

  10. #10
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hammer65 View Post
    calc_found_rows query
    SQL_CALC_FOUND_ROWS is not a separate query it is part of the one query. It doesn't take extra resources to collect this information as the work has to be done anyway.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •