Im working on some graphical representation of visitor tracking to a website and having trouble passing a specific data set to the image generator.
The data set for plotting is generated dynamically from a mysql query, essentially taking the 5 highest country counts and getting the name and count in a while loop.
while($row = mysqli_fetch_array($origin_result, MYSQL_ASSOC))
{
$origin[] = $row['origin'];
$count[] = $row['count'];
}
The final data will be country1 = count1, country2 = count2..etc up to country 5
The data needs to be sent via a $_GET variable as its going to a php page to generate a graphical representation of the data.
the receiving page has to end up with data in this format
$data = array("CBS" => 6.3, "NBC" => 4.5,"FOX" => 2.8, "ABC" => 2.7, "CW" => 1.4);
Ive tried generating an associative array using
while($row = mysqli_fetch_array($origin_result, MYSQL_ASSOC))
{
$origin = $row['origin'];
$count = $row['count'];
$origin_data[] = '*' . $origin . '* ^ ' . $count;
}
then using implode to create a string to pass through a $_GET variable with a _ separator and using * in place of " and ^ instead of => so as to not interfere with the url
$origin_data = implode("_",$origin_data);
on the receiving page im using the following to reconstruct the array
$chart_data = array();
//get quotes back
$raw_data = str_replace('*','"',$_GET["raw_data"]);
$raw_data = str_replace('^','=>',$_GET["raw_data"]);
$raw_data = str_replace('_',',',$_GET["raw_data"]);
//get array back
$raw_data = explode("_", $raw_data);
$chart_data = $raw_data;
$data = $chart_data;
but it cant read it correctly. Ive spend 2 days trying different approaches and im at a loss for another idea.
How does one construct an array of the form "name" => value in a loop and pass it through a $_GET variable to a php page then reconstruct the array in the required format.