I am optimizing some code. Some code I can change, some I can't. I am querying the database and checking it against a json_decode() array that is the new data. I find the differences and add or delete from the database as needed.
UPDATE: This is my query:
$sQuery = "SELECT column1, column2 FROM my_table WHERE id=my_id;
UPDATE2:
OK, so my query goes into a custom query function that I cannot change and this is what comes out:
mysqli_result Object
(
[current_field] => 0
[field_count] => 2
[lengths] =>
[num_rows] => 2
[type] => 0
)
I want to parse the result in such a way that is organized like this:
Array
(
[0] => Array
(
[column1] => value
)
[1] => Array
(
[column2] => value
)
)
// end Update 2
I'm banging my head feeling stupid trying to parse the first array to match the organization of the second array. Help please?
Here is what I've tried:
while ($aRows = $aResults->fetch_assoc()) {
foreach ($aRows as $iKey => $sValue) {
if ($iKey % 2 == 0)
$aPreviousList[$iKey][] = $sValue;
if ($iKey % 2 == 1)
$aPreviousList[$iKey][] = $sValue;
}
}
But it comes out like this:
Array
(
[ixfChangeMethod] => Array
(
[0] => 16
[1] => 11
)
[sDetails] => Array
(
[0] => some details about 16
[1] => some details about 11
)
)
Am I going about this all wrong or is there another way I can parse both arrays that I can check the differences better?
fetch_assoc()should return a row where each member of the array is the name of the column... what does your query look like?