SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New mysql query Vs working on existing results

    Lets say I've obtained a set of over 100 items using a single mysql query and displayed them. Now, I need only the items with a certain id. Am I better off using a new mysql query or working on the existing results using PHP conditional statements?

  2. #2
    SitePoint Zealot
    Join Date
    Jan 2006
    Location
    Gold Coast, Australia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not get the items with the matching ID initially via SQL?

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because I need to display all the items before displaying those with a certain id.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    If you already know what ID you need when you get the original set of data, why not do both at once?

    Nothing stops you from running the id check during the display loop, and storing the results or whatever you want to do for later use.

    1 loop through data is better than 2 loops.

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2006
    Location
    Gold Coast, Australia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you need to get all 100 of them anyway? Well in that case you just need to sort them out via PHP. No use making another mysql connection.


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
  •