SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to paginate in case of SELECT * AGAINST ?

    Hi,

    When generating a LIST via SELECT AGAINST then LIMIT X, Y does not work.
    That is if the SELECT statemenet is like:

    SELECT ix_id, title, descpt FROM customers WHERE MATCH (title, descpt)
    AGAINST('$find') LIMIT 90, 100

    Rather than getting the results from 90 to 100 MySQL returns all 100 results!

    So how can one pageinate in case of SELECT * AGAINST?

    To put it another way, since MySQL returns all 100 values rather than from
    90 to 100 only, how can we then effectively execute:

    while ($result_chk_word = mysql_fetch_array($query_chk_word)) {

    $url_id = $result_chk_word['ix_id'];
    $title = $result_chk_word['title'];
    $descpt = $result_chk_word['descpt'];

    }


    to list results for only 90 to 100?

    Regards,

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    what was the value you used for $find? how many rows were supposed to have been found? how many total rows in the table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Well $find can be any value, in this case for Test purposes it is "Money".
    It returns 4372 rows.
    Total rows in the Table are in Million+.

    So what I would like to do is to for example have it return results from LIMIT 20, 30
    but instead it returns all 30. So rather than behaving like a normal SELECT and
    return values between LIMIT 20, 30 this type of SELECT returns all values from 0
    to 30!

    Regards,
    dean

    Quote Originally Posted by r937 View Post
    what was the value you used for $find? how many rows were supposed to have been found? how many total rows in the table

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    well, i don't know what's happening, all i can do is guess

    try using a subquery...
    Code:
    SELECT *
      FROM ( SELECT ix_id
                  , title
                  , descpt 
               FROM customers 
              WHERE MATCH (title, descpt) AGAINST('$find') ) AS q
    LIMIT 90, 100
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    San Sebastian, Spain
    Posts
    93
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I would also include an order by clause to make sure that the results are always returned in the correct order.


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
  •