Is it possible to create a query from a query in PHP?

Discussion in 'PHP' started by LaPoChE, Aug 2, 2006.

  1. #1
    Hey,

    Is it possible to create a query from a query in PHP. I know you can do this in Cold fusion.

    Cold fusion Example:

    <cfquery name="getUser" datasource="DSource">
    select * FROM users
    </cfquery>

    <!--- Query from a query --->
    <cfquery name="getUser" dbtype="query">
    select * FROM users where uerid = 256
    </cfquery>

    I'd like to be able to do this in PHP, so if anyone could help me out it would be great,

    thanks
     
    LaPoChE, Aug 2, 2006 IP
  2. rjb

    rjb Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am not a performance expert, nor do I know coldfusion, but I am not sure why the extra step is needed...

    Maybe you could explain what you are trying to do.

    In any event... you could just sort through the returned array instead of running a 2nd query.
     
    rjb, Aug 2, 2006 IP
  3. LaPoChE

    LaPoChE Active Member

    Messages:
    198
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    The reason i'd like to do this is because the query i'm running returns a huge number of results and takes a while... By using a query from query I only need to go to the DB once, and then get what i need from the 2nd query. This way the page will load alot faster.
     
    LaPoChE, Aug 2, 2006 IP
  4. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hey thats exactly what rjb is talking about. You just query the database once and get the results into an array with mysql_fetch_array or mysql_fetch_row, to get rows one at a time. The DB is queried only once and then you only have to process the array.

    Thomas
     
    coderlinks, Aug 3, 2006 IP
  5. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #5
    Shoemoney, Aug 3, 2006 IP
  6. LaPoChE

    LaPoChE Active Member

    Messages:
    198
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    Thanks alot, this should work fine
     
    LaPoChE, Aug 3, 2006 IP