#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    40
    Rep Power
    2

    Smile Search and Pagination PHP


    Hello friends,

    I've been stuck for a while now on getting a search bar to work with my pagination script. I know how to create a text box and generate searches. But I am stuck on getting the next pages to work. I have tried several / websites and tutorials, and I'm getting close. Any tips or suggestions are appreciated.

    If it is too unclear I will post a snippet of my code.

    Hopefully sombody more brilliant than I in PHP will be able to help me with this problem.

    Thanks guys.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398
    It's somewhat clear but code would still help.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    40
    Rep Power
    2

    Re:


    I have a lot of PHP code, so here's a snippet.

    PHP Code:
    $pagination "";
        if(
    $lastpage 1)
        {    
            
    $pagination .= "<div class=\"pagination\">";
            
    //previous button
            
    if ($page 1)
                       
                           
    $pagination.= "<a href=\"$targetpage?page=$prev\"> <br />  <br />  <br />Previous</a>"
                        
                            else {
                
    $pagination.= "<span class=\"disabled\"><br />  <br />  <br />Previous</span>";    
                            }
            
    //pages    
            
    if ($lastpage + ($adjacents 2))    //not enough pages to bother breaking it up
            
    {    
                for (
    $counter 1$counter <= $lastpage$counter++)
                {
                    if (
    $counter == $page){
                        
    $pagination.= "<span class=\"current\"></span>";
                                            
    $pagination.= "<a href =\"$targetpage?page=$counter\"></a>";
                                          
                            }} 
    The search box is simple and looks like this:

    Code:
    <input type='text' size='90' name='search'></br></br>
    <input type='submit' name='submit' value='Search source code' ></br></br></br>
    Now what I can't figure out is how to incorporate this part of my PHP into the above pagination without ruining the pagination.

    Code:
    $limit = $_GET['search']
    
    $result = mysqli_query($con, "SELECT * FROM $tbl_name WHERE Description LIKE % $limit % ORDER by date DESC LIMIT $start, $limit" );
    I'm not worried about security at this point - just getting to work.
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398
    I don't know what you're doing with $limit in that code. Is it the search term or the number per page? And where's the quotes around the search term in the SQL?
    PHP Code:
    $search $_GET["search"];
    $result mysqli_query($con"SELECT * FROM $tbl_name WHERE Description LIKE '%" mysqli_real_escape_string($con$search) . "%' ORDER by date DESC LIMIT $start$limit"); 
    That's all I can say for now given the two wholly separate pieces of code you posted.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    40
    Rep Power
    2

    Re:


    $limit is the number of entries per page.

    I understand what you wrote with the PHP code.

    But how do I incorporate that code so it works when I click one of the NEXT links?

    Sorry if my question is confusing
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,055
    Rep Power
    9398
    Change $start accordingly. I don't know how because you still haven't posted that part of the code.

IMN logo majestic logo threadwatch logo seochat tools logo