The issue: renaming array keys inside a foreach loop.
I'm trying to build a pie chart image with the Google Chart API using information from a database. (I'm going to change the type of data I talk about because it is extremely sensitive. Just wanted to share that so you didn't think my example was completely weird or stupid even.)
After running my SELECT statement, I have a 2-column dataset with multiple rows. I am currently grabbing the data in this way:
<?php
$total = 0;
while ($r = mysql_fetch_array($result))
{
$info[$r['month']] = $r['days'];
$total += $r['days'];
}
?>
$info is an array with each key being the name of the month and the value being how many days are in that month. $total is the sum of each days.
To supply the dataset inside the image src, I provide a comma separated list. To supply the labels for each dataset, I provide a list separated by pipes.
The problem that I am having is that I would like each label to be the month as well as a percentage number of the total in parenthesis next to the month name.
I am building the URL perfectly fine using JUST the month name like this:
<?php
echo '<p>';
echo '<img src="http://chart.apis.google.com/chart?cht=p&chd=t:';
echo implode(',',array_values($info));
echo '&chs=250x100&chl=';
echo implode('|',array_keys($info));
echo '" alt="" />';
echo '</p>';
?>(I broke up each line for readability.)
How I am trying to include the percentage in the label is be redefining the key BEFORE I add in the array keys to the URL. Trying by this method:
<?php
foreach ($info as $key => $value)
{
$key = $key . (number_format($value/$total,0)) . '%';
}
?>
Expected outcome:
The labels on the image would read something to the tune of -- June (8.2%)
Actual outcome:
Nothing. Well, not nothing. Just the month is coming out. The key names are not being edited.
Thanks for reading this far. I appreciate the help
Does design fit in FPGA ?
Hi all,I've made a large HCC-Design. Because of the program-size the compile process with the handel-c compiler takesvery long. Is there any possibility to find out whether the design fits into my
How do I use a global footer..?
If my index.php has a bole bunch of if functions and exit's in them
random generation
hii need help with generating thisnumbers from 1-12i want to generate in random order 60 times in total the numbers 1-12and generate 5 results from each number.so in the total of the 60 return result
Executing an exe
Hi. I have some bizarre problem with exec (other any other method) to launch exe's. I am making a game server booking system and the part that is not working is the one with the launching the server
Table Control
Hi Guru's,
Remove values in array2 from array1
I have two arrays.Array 1 is where the array key holds various different numbers. For example:Code: [Select]$array[32] = 1;$array[122] = 1;$array[238] = 1;$array[324] = 1;The other array holds values
Intrastat Report Config in ECC 6.0 - goods Movement in EU countries
Colleagues, need ur help to understand the changes require in ECC 6 standard Report configuration settings.
Show specific day of the week
I have been racking my brain trying to get this function to work properly and it is doing so for everything but Sundays. What I am trying to do is display all dates within a specified date range that
WORDPRESS - Multiple Loops Only Going to One Post?
I have various pages with multiple loops and i need them to be individual to all other categories.2 columns.Left column shows 4 posts from category news just with the date and some custom
Loop column after 2 results
Hello All.Here is what I have:Client ID Company name Client ID Company nameI then need a script to echo 2 results per row then start a new row.I've tried many