Jump to content

PHP Search Pagination Help Need - [URGENT]


BlackTyger

Recommended Posts

This website has been great so far. Whenever I post a question, I get answer within few minutes. I have another question today related to PHP pagination.

 

My search page basically allows users to view users others users in a specific country. Basically, there is are two html drop downs on the search page. First one allows you to select gender (male or female) and other one allows you to select country. After the search button is pressed, it displays all the usernames of males in that country.

 

my search page's url looks something like:

http://localhost/search.php?gender=Male&country=Canada&searchbutton=Search

 

I want to add pagination to this script. the search form has method=GET and 3 input options. one is gender and the other one is country and the last one is pageNum which is hidden. how can i add pagination to this???

 

Link to comment
Share on other sites

If you don't post code on how the information is currently being displayed/handled there isn't much guidance you'd be able to get.

 

If you don't want to post your code that's fine. But you'd have to do it in steps with what you currently have.

 

You can find premade functions here:http://www.phpeasycode.com/pagination/

 

1 - You'd have to build the first portion of your query.

  $search_query = "SELECT * FROM table";

 

 

2 - You'd have to then generate the where portion of your initial query based on that information.

 

$search_query .= "WHERE gender = male/female"; // Or whatever post variables you have assigned to handle that.

 

 

3 - Use Case's to sort the information and add $sort or something to your ORDER BY clause in your query statement.

 

    // Sort the search query using the sort setting
    switch ($sort) {
    // Ascending by username
    case 1:
      $search_query .= " ORDER BY username";
      break;
    // Descending by gender
    case 2:
      $search_query .= " ORDER BY username DESC";
      break;
    defualt:
      // No sort setting provided, so don't sort the query
}

 

4 - Generate your ouput based on the sort selection requested by the user:

 

5 - Setup limitations on how much data per page you'd want to display

 

6 - Put the pieces of the query back together to make a full query statement

 

7 - Generate the output from the query

 

8 - Generate the page links

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.