SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Emulating MySQL queries with PHP

    Just so I don't have to query 200 times the MySQL db when listing 200 members' info in a memberlist table, I was wondering how to emulate SELECT, ORDER BY, etc statements with a PHP table ?
    What I would try is make a big SELECT * FROM members, and then process everything with PHP, but the problem is this table needs to be ordered according to members' levels, which would be easy if they didn't have more than one level, thus making the ORDER BY user_level irrelevant since user_level is a CSV string that contains stuff like "4,5,2" that is parsed to see which level we're talking about.

    I don't know if my point is clear enough... Anyway, what I would need to know is how I could emulate these common MySQL queries with a PHP table... Any hint ?

  2. #2
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not clear to me what information you need and where it's stored. If possible, maybe show what queries you would perform in mysql to get the info you need, or explain a little more clearly how you want to order your results. If you can do it in mysql, you can do it in PHP.

    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Emulating MySQL queries with PHP

    Originally posted by Shin Ma
    but the problem is this table needs to be ordered according to members' levels, which would be easy if they didn't have more than one level, thus making the ORDER BY user_level irrelevant since user_level is a CSV string that contains stuff like "4,5,2" that is parsed to see which level we're talking about.
    the problem is that you don't have your tables designed right. that's why you should never try to put something that should be in seperate columns into a CS string! i suggest you redesign your tables.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately, I couldn't design them another way if I want to be able to allow an unlimited number of levels. I could do user_level1, user_level2, etc, but that's not how i see it.

    What I would do, is make a big SELECT query on the users table, then check how many levels there are, for users, and create temporary columns in the php table, that way I would sort the users from their user_level1, or user_level2, ad infinitum.
    The only thing I wonder, is how to order a table by one of its column...

  5. #5
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Please post table layout of all tables involved - we cannot help you if we cannot see what you are trying to do.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  6. #6
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You keep referring to a 'php table' as if you are talking about a virtual database table. As far as I know, nothing like that exists. What you could do is make your query and populate php arrays with the info, then parse through the arrays and order the info any way you like. Is this what you are referring to?

    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  7. #7
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please post your tables... it sounds like to me that you could improve it with better design. Do you know how to normalize a table?


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
  •