arrays
Posted: Thu Oct 28, 2010 10:55 am
Maybe I'm making this more complicated than it needs to be, but:
I am running a MySQL query, out of this I want to put the headers into an array. I then want to put the result of the query into another array, but using the headers as the reference in the array, so that when I come to look at the data later I can reference it by the original column names.
what I have is:
and I think I'm just going round in circles with it. any help appreciated
I am running a MySQL query, out of this I want to put the headers into an array. I then want to put the result of the query into another array, but using the headers as the reference in the array, so that when I come to look at the data later I can reference it by the original column names.
what I have is:
Code: Select all
$dbs = "schema";
$query_array = array();
$query_array[] = array( 'query' => "SHOW SLAVE STATUS",
'name' => "slaveStatus");
$slaveState_array = array();
$slaveHeader_array = array();
$printed_headers = false;
for($a = 0; $a <sizeof($slaveRes_array); $a++) {
$con = mysql_connect($slaveRes_array[$a]['server'], $slaveRes_array[$a]['user'], $slaveRes_array[$a]['password']);
mysql_select_db($dbs, $con);
$dbName = $slaveRes_array[$a]['database'];
for($b = 0; $b <sizeof($query_array); $b++) {
$result = mysql_query($query_array[$b]['query'], $con) or print("<p>ERROR:</p>".mysql_error());
if ( !$result ) { goto end;}
while($row = mysql_fetch_assoc($result)) {
if ( !$printed_headers )
{
//print the headers once:
//for($c = 0; $c <sizeof($row); $c++) {
for($c = 0; $c <sizeof($row); $c++) {
foreach ( array_keys($row) AS $header )
{
$slaveHeader_array[$c] = array($header);
print sizeof($row);
print $header;
}
$printed_headers = true;
}}
foreach ($row as $attribute)
$slaveState_array[] = array($query_array[$b]['name'] => $attribute);
}
mysql_close($con); }}
end: