How could I make this query work?

I'm using highcharts to create a graphic representation of a dataset. Part of the code looks like what I've got written below:

$categories_query=mysqli_query($conn, $q2);
			$categories_count=mysqli_num_rows($categories_query);
			$categories_number=1;
			while($categories_row=mysqli_fetch_assoc($categories_query))
			{
				$body.="{\nname:'";
				$body.=stripslashes($categories_row['REGION']);
				$body.="',\ndata: [";
				if($_GET['kpi']=="DNS_FAILURE_RATE")
				{
				$body.=number_format($categories_row['DNS_FAILURE_RATE'], 2);
				}
				$body.="]\n}";
				if($categories_number<$categories_count)
					{
					$body.=",";
					}
			$catgories_number-$categories_number+1;
			}

Open in new window


My focus is "DNS_FAILURE_RATE." That's the name of the column in the table that I want to retrieve data from.

Right now, I've got things set up as an "if" statement. Thing is, I've got 21 different scenarios I need to address. Instead of an "if" statement, I want to do something like this:

while($categories_row=mysqli_fetch_assoc($categories_query))
			{
				$body.="{\nname:'";
				$body.=stripslashes($categories_row['REGION']);
				$body.="',\ndata: [";
				$body.=number_format($categories_row['$_GET[kpi]'], 2);
				$body.="]\n}";
				if($categories_number<$categories_count)
					{
					$body.=",";
					}
			$catgories_number-$categories_number+1;
			}

Open in new window


Notics the "$body.=number_format($categories_row['$_GET[kpi]'], 2);" - that's what I'm trying to figure out.

Can you smell what I'm cookin'?

I don't get any errors, but I don't get any data. When you look at the source code of the graph, instead of getting this (data: [real numbers]):

series: [{
name:'CENTRAL TEXAS',
data: [3.46]
},{
name:'HOUSTON/GULF COAST',
data: [3.17]
},{
name:'MOUNTAIN',
data: [3.01]
},{
name:'NEW ENGLAND',
data: [2.74]
},{
name:'NY METRO/NNJ',
data: [2.72]
},{
name:'PA/WV/OHIO',
data: [3.15]
},{
name:'PHILADELPHIA',
data: [2.98]
},{
name:'SOUTH CENTRAL',
data: [3.17]
},{
name:'SOUTHWEST',
data: [3.00]
},{
name:'UPSTATE NY',
data: [2.82]
},{
name:'WASH/BALT/VA',
data: [3.20]
},{
name:'CAROLINAS/TENNESSEE',
data: [2.96]
},{
name:'FLORIDA',
data: [3.26]
},{
name:'GEORGIA/ALABAMA',
data: [4.70]
},{
name:'GREAT PLAINS',
data: [3.13]
},{
name:'ILLINOIS/WISCONSIN',
data: [3.43]
},{
name:'KANSAS/MISSOURI',
data: [3.19]
},{
name:'MICHIGAN/INDIANA/KY',
data: [3.11]
},{
name:'NORTHERN CALIFORNIA/NEVADA',
data: [3.05]
},{
name:'PACIFIC NORTHWEST',
data: [2.98]
},{
name:'SOUTHERN CALIFORNIA',
data: [2.72]
},]
		});

Open in new window


...I get this (data:[0.00]:

series: [{
name:'CENTRAL TEXAS',
data: [0.00]
},{
name:'HOUSTON/GULF COAST',
data: [0.00]
},{
name:'MOUNTAIN',
data: [0.00]
},{
name:'NEW ENGLAND',
data: [0.00]
},{
name:'NY METRO/NNJ',
data: [0.00]
},{
name:'PA/WV/OHIO',
data: [0.00]
},{
name:'PHILADELPHIA',
data: [0.00]
},{
name:'SOUTH CENTRAL',
data: [0.00]
},{
name:'SOUTHWEST',
data: [0.00]
},{
name:'UPSTATE NY',
data: [0.00]
},{
name:'WASH/BALT/VA',
data: [0.00]
},{
name:'CAROLINAS/TENNESSEE',
data: [0.00]
},{
name:'FLORIDA',
data: [0.00]
},{
name:'GEORGIA/ALABAMA',
data: [0.00]
},{
name:'GREAT PLAINS',
data: [0.00]
},{
name:'ILLINOIS/WISCONSIN',
data: [0.00]
},{
name:'KANSAS/MISSOURI',
data: [0.00]
},{
name:'MICHIGAN/INDIANA/KY',
data: [0.00]
},{
name:'NORTHERN CALIFORNIA/NEVADA',
data: [0.00]
},{
name:'PACIFIC NORTHWEST',
data: [0.00]
},{
name:'SOUTHERN CALIFORNIA',
data: [0.00]
},]
		});

Open in new window


What am I doing wrong and how can I fix it? I want to introduce the column name directly via the $_GET['kpi'] dynamic rather than having to write out 21 different if/else scenarios.

What do you think?
brucegustPHP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
I think the quotes may be misused in this line (and maybe others, TL;DR)

$categories_row['$_GET[kpi]']

Single quotes prevent variables substitution.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.