Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts

    search form errors

    I have 2 problems and I can't find them.
    1. when no results found... I don't get the message "0 results".
    2. when found 90 results (for example) and list them 20/page, when I click [page 2] I get page 2 from all data listed (not only those 90 results).

    PHP Code:
    $conn mysql_connect($dbhost$dbuser$dbpass);
            if (
    $conn){
            
    mysql_select_db("dbname"$conn);
            
    $per_page 20;
            
    $pages_query mysql_query ("SELECT COUNT('ID') FROM table WHERE column LIKE  '%$word%'  AND  column LIKE '%$word%'");
            
    $pages ceil(mysql_result($pages_query0) / $per_page);
            
    $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
            
    $start = ($page 1) * $per_page;

            
    $query "SELECT * FROM table WHERE column LIKE  '%$word%'  AND  column LIKE '%$word%' LIMIT $start, $per_page ";

            
    $query_list "SELECT * FROM table WHERE column LIKE  '%$word%'  AND  column LIKE '%$word%' ";
            
    $results_list mysql_query($query_list) or die(mysql_error());
            
    $results mysql_query($query) or die(mysql_error());
            
    $count mysql_num_rows($results_list);
            if(
    $count >=1){
                
    $search_output .="<hr />$count rezultats <br />";
                while (
    $row mysql_fetch_array($results)){
                    
    $search_output .= " blablablabla";
                    }
                if(
    $pages >= && $page <= $pages){
                    for (
    $x=1;  $x<=$pages$x++){
                         
    $page_numerotation .= ($x == $page) ? '<strong>' $x '</strong> ' '<a href="?page=' .$x'"> ' $x '</a> ';
                        }
                    
            }else{
                
    $search_output "<hr /> 0 rezultats. <hr /><br />";
                die(
    mysql_error());}
                
    }
    }




    and if can anyone help me with an easy pagination
    1 to 10 page links than use <back and next> or something like that...

    ty in advance

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I don't know why you have a $query_list in here at all. Since this one is not limited like the count or the dataset, basing your count on this will not provide an accurate representation of the data at hand. Everything should come from the $query query you have.
    As for your second, where does $word come from? The behaviour you are describing is that it matches all records indicating your search criteria is %% and $word is undefined. If you paginate with a filter, you have to provide that filter as a part of the request.

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts
    $query_list is there because (I don't know why) when I found more than 20 results... the count was exact 20 (the number of results/page). So I "decide" to make a new query just for list the results, because the count id query just doesn't to hes work

    and for the query of $word... yes... is query to match 2 words... and they are defined... before the connect line. this isn't my problem....

    the code works fine... less side presented on the firs post...

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The $query_list is not required. If its for a count, use what you pulled from the COUNT() call.

    Show where $word is defined.

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I have one but... it works only to show how many results will be divided/page...
    but what about my problems....?!?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by _user View Post
    I have one but... it works only to show how many results will be divided/page...
    but what about my problems....?!?
    Quote Originally Posted by Fou-Lu View Post
    Show where $word is defined.
    This.

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i used another code... and I have same problems...
    well...
    I used $word to change the name here
    there are 2 $
    $word1 and $word2.
    its a search form using 2 dropdown menus.
    column1 = colors: red, blue, yellow
    column2 = size: S, M, L

    when user select from dropdown red and M

    i have
    PHP Code:
    if($_GET){
    $color $_GET['color'];
    $size $_GET['size']; 
    so the query is something like this
    PHP Code:
    SELECT FROM table WHERE color LIKE  '%$color%'  AND  size LIKE '%$size%' 

    I used this because I`m not familiar with arrays and stuff

    so...
    what could be the problems?

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Not sure how I overlooked this one today.
    How are you building your pagination links? The first block of code you have doesn't pass the $word anywhere within it, only the page represented by $x. As mentioned, you need to provide this query on every request.

  • #9
    New Coder
    Join Date
    Feb 2012
    Posts
    40
    Thanks
    0
    Thanked 9 Times in 9 Posts
    At a quick glance I noticed the only way that would show your 0 results output is if it can't connect to the database. You have to make an else statement inside the last bracket.


  •  

    Posting Permissions

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