How to use mysql query result for another query?

Discussion in 'PHP' started by KingCobra, Sep 27, 2011.

  1. #1
    Suppose I have a mysql table with 1000 rows.

    I can run a query to get my desired rows (suppose 10 rows), its really easy.

    But after getting those 10 rows I want to run a separate query on those 10 rows to get more specific result from that.
    (I am not wanting to make query over 1000 rows again. Because my desired rows are inside those 10 rows. It will make me faster for execution.)
    (Its not sub query)

    So would you please show me using php how can I store my first query result in memory or temp or (you know) and run next time another query over the first query result?

    Thnaks
     
    KingCobra, Sep 27, 2011 IP
  2. SheetalCreation

    SheetalCreation Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #2
    $result = mysql_query( say your first query is here);
    $result variable is storing your 10 interest result already in some temp location.
    what you need to do is you need to traverse through each row in $result and check for the second condition.To do that :
    while($row = mysql_fetch_array($result))
    {

    }
     
    SheetalCreation, Sep 27, 2011 IP
  3. SheetalCreation

    SheetalCreation Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #3
    $result = mysql_query( say your first query is here);
    $result variable is storing your 10 interest result already in some temp location.
    what you need to do is you need to traverse through each row in $result and check for the second condition.To do that :
    while($row = mysql_fetch_array($result))
    {
    $row variable is having each row one by one
    so here you can check whether $row is of your interest or not.
    }

    let me know if u need further help for same.
    Sheetal
     
    SheetalCreation, Sep 27, 2011 IP