0

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.

  • http://stackoverflow.com/questions/5098397/how-to-pass-an-array-in-get-in-php – user1844933 Aug 13 '16 at 13:34
  • why are you using `GET` requests? Query args are not meant to send data although you can force them to. Feels a bit like trying to squeeze the square peg in a round hole. `POST` was made specifically for this purpose – BeetleJuice Aug 13 '16 at 13:55
  • The php page is called as an image, so by sending it as GET im telling it what to generate. I thought it would be better so i dont have to write code for every graph, just write it to take an array and other variables and display them – user5899878 Aug 13 '16 at 14:16

0 Answers0