Hi,

I am having a trouble with foreach loop and MySQL queries. The loop is extremely slow while pulling out the data from MySQL database.

Here is the example code:

PHP Code:
class Report
{
........
function 
getUsers()
{
    
$this->db->query "SELECT id,Name FROM Users WHERE Creator=12 AND id!=22 ORDER BY Name ASC";
    
$this->db->Query();
    
$result=array();
    while(
$row $this->db->FetchArray()) 
    {
        
$result[]=$row;
    }
    return 
$result;
}
...........
}

$users = new Report();
foreach (
$users->getUsers() as $row)
{
    
$id $row['id'];
    
$number_of_new_tickets $users->getNumbers($id,"new","$dates[0]$dates[1]%");
    .....................

As you can see, I have class Report that uses class MySQL for handling mysql things like queries etc, and then I am using that class Report inside foreach loop to pull out data. The problem is that it takes about 50 seconds to get data for 10 users with some statistics. I have to say that the database itself is huge, so I understand it might be the issue, but after trying some basic debugging, I found out that the slowdown is happening inside the foreach loop, because that's where it hangs every time it gets executed. So I am wondering if there is a better way of doing this, because I am using foreach loop, while loop inside functions, and all together its very slow.

Any help appreciated.