SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for the esoteric subject line, but I couldn't think of anything better. I'm using PHP to search a MySQL database, and I want to limit the number of matches displayed to 20 per page. But I also want to know the total number of matches. This kind of thing is seen all over the place, and I know how to do it with two separate SQL queries to the database. But is there a way to do it with a single query? Or should I not worry about this as a performance issue?

    For example (and I'm being very loose here):

    First Query: "SELECT Count(*) FROM Table_Name"
    $total_matches=mysql_num_rows;

    Second Query: "SELECT * FROM Table_Name LIMIT 20"
    etc...

    Is this bad? Should I be trying to do this with just one MySQL query? Thanks!

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't worry about it - I can't think of a way to do what you need with one query on MySQL.
    It shouldn't affect performance a lot


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
  •