Jump to content

After Mysql_Fetch_Assoc To Assocative Array Inserting Record


AnalyzeThis

Recommended Posts

Hi,

I am trying to insert a custom record into a assocative array made from a mysql_fetch_assoc. The amount of rows differs depending on what is fetched sometimes there is very few. I need to insert a row into the fetch where there is none. I.e. there are no records for Oct or Dec so we need to make some up and place them into the array. So I was taking a array from it, i.e. Nov and then trying to modify that array to be "Jan." and all "0"s and then array_splice($records, $count, 0, $gen) it back into the array where needed; which is working fine.

 

What I am having trouble with is changing the values within the one line that I took to insert back after modified.

 

+-------+----------+-------

Month | bla | bla | etc..

+-------+----------+-------

| Oct | 0 | 0

| Nov | 1 | 0

| Dec | 0 | 0

+-------+----------+-------

 

The assocative array print_r looks something like:

 

gen = Array ( [0] => Array ( [0] => January [Month] => January [1] => 2012 [Year] => 2012 [2] => 0.103813 [topping] => 0.103813 [3] => 91.52665 [topping1] => 91.52665 [4] => 33.31605 [topping2] => 33.31605)

 

How would I go about changing all the fields in the array to "0" and the Month field to "xxx"? I am having trouble working with this data type due to its structure.

Still need to optmize it but I figured it out.

 

$i = 0;

$count = 0;

$gen = array($records[0]);

$temp = array_keys($gen[0]);

for($x=0; $x<count($temp); $x++){

$gen[0][$temp[$x]] = NULL;

}

 

while ($mydate < $timespan["end"]){

$mydate = strtotime ("+$i month", $timespan["start"]);

if ($records[$count]["Month"] == date("F", $mydate)){

$count++;

} else {

$gen[0][0] = date("F", $mydate);

array_splice($records, $count, 0, $gen);

}

$i++;

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.