Basically what I have so far is:
Code: Select all
//list of all database connections
$connections_array[6] = array('server' => '1.2.3.4',
'user' => $u,
'password' => $p,
'database' => 'MF1',
'sendmail' => '0',
'repeat' => '0',
'dbID' => '07',
'default' => 'test'
);
//the database required here
$mfA_array = $connections_array[6];
//List of MyQSL queries
$q1 = "SELECT COUNT(*) AS 'count' FROM mf1 WHERE LEFT(`starttime`,10) = CURDATE() AND `customerid` =";
$q2 = ...
$q3 = ...
//mf query_array
$mfquery_array = array();
$mfquery_array[] = array( 'query1' => $q1
//'query2' => $q2,
//'query3' => $q3
);
//list of Customers
$Aarray[] = array( 'name' => "Cust1",
'id' => "5664");
$Aarray[] = array( 'name' => "Cust2",
'id' => "5585");
$Aarray[] = array( 'name' => "Cust3",
'id' => "5584");
$Aarray[] = array( 'name' => "Cust4",
'id' => "5665");
$Aarray[] = array( 'name' => "Cust5",
'id' => "5652");
$Aarray[] = array( 'name' => "Cust6",
'id' => "5654");
//Run the queries and put the result into an array
$con = mysql_connect($mfA_array['server'], $mfA_array['user'], $mfA_array['password']);
mysql_select_db($mfA_array['default'], $con);
foreach($mfquery_array as $query) {
foreach($Aarray as $cust) {
// QUERY 1
$fquery = $query['query1'].$cust['id'];
$Mfres1 = mysql_query($fquery);
if ( !$Mfres1 ) { $error = mysql_error();
print $error;
}
while($Mfrow1 = mysql_fetch_assoc($Mfres1)) {
$totalJobs[$db['database']] = $Mfrow1;
$Aarray[] = array('count' => $Mfrow1['count']);
}
// QUERY 2
// QUERY 3
}
print_r ($Aarray);
}
mysql_close($con);
1. I connect to the database
2. I get a list of queries to run against that database
3. I get a list of customer ID's to insert into the queries
4. I run each query with the customer ID added, and then add the result to the $Aarray
So what I want to end up with is something like:
print_r ($Aarray)
Array (
[0] => Array (
[name] => Cust1
[id] => 5664
[count] => 100
)
.....
What I am currently getting is
Array (
[0] => Array (
[name] => Cust1
[id] => 5664
)
. . . . .
[6] => Array (
[count] => 100
)
[7] => Array (
[count] => 120
)
. . . . .
As you can see the count values are being added to the end of the array as a separate element, instead of being associated with the relevant customer.
How can I get the value to associate with the relevant customer?