Results 1 to 5 of 5

Thread: In PHP/MySQL 5 loops, to appear qeuries results, well can I nest queries ? [b]What so

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default In PHP/MySQL 5 loops, to appear qeuries results, well can I nest queries ? [b]What so

    In PHP/MySQL 5 loops, to appear qeuries results, well can I nest queries ? What solutions exist ? This is due to the fact that, I need data from first query to input continuously to second query ?

  2. #2
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    place a while loop inside a while loop... If u place an example code, then it will easy to tell you how to input data from first query to second query

  3. #3
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Select * From $affTable;

    $AID=row['AID'];
    Select SUM(total) AS TOTAL From $bookingTable Where AID='$AID';

    // HOW I GET EACH AFFID(=AID) FROM FIRST QUERY AND RUN SECOND QUERY TO LIST TOTAL EARNINGS(=TOTAL) ?

  4. #4
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    Hope this helps

    Code:
    $query = mysql_query("Select * From $affTable ");
    
    while ($row = mysql_fetch_array($query))
     {
      $AID = $row['AID'];
      $query2 = mysql_query("Select SUM(total) AS TOTAL From $bookingTable Where AID='$AID' ");
      
        while  ($result = mysql_fetch_array($query2))
                 {
                  \\do whatever you want to do with the values here
        
                 }
      
      
     }

  5. #5
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    The:
    while ($row = mysql_fetch_array($query))
    may be like:
    $count = @mysql_num_rows($result);
    while ($i < $count) {
    ???

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
  •