Log in

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



leonidassavvides
04-13-2009, 09:58 AM
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 ?

borris83
04-14-2009, 12:37 AM
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

leonidassavvides
04-14-2009, 04:11 AM
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) ?

borris83
04-14-2009, 08:44 AM
Hope this helps


$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

}


}

leonidassavvides
07-06-2009, 09:11 PM
The:
while ($row = mysql_fetch_array($query))
may be like:
$count = @mysql_num_rows($result);
while ($i < $count) {
???