how to display the right hightchart category base on database value

hi guys, I am using hightchart libery to display data from my database into charts. i want to implement the following: fetch all departments and count how many time they are using the various conference rooms. (the three departments are: Administration, Health Services, Planning and the three conference rooms are: room227,room327 and room427)

the problem in the below script  is that, take for an example, i have only one entry for one department in the database which is Health Services, room327, if  this happen, the chart display  room227 to be the one that own the data because the category of the chart starts with room227.

the interpretation on the chart is  that room227 is the one that is booked , which is not the case in reality: in the database it shows that room327 is the one that is booked by Health Services.

see the script blow


            
	$sql21 = "SELECT count(room_id) as count1 FROM mohconferenceroom where department = ('ADM') GROUP BY (room_id) ORDER BY room_id";

	$viewer = mysqli_query($mysqli,$sql21);

	$viewer = mysqli_fetch_all($viewer,MYSQLI_ASSOC);

	$viewer = json_encode(array_column($viewer, 'count1'),JSON_NUMERIC_CHECK);
	
	
	


	

	$sql22 = "SELECT count(room_id) as count2 FROM mohconferenceroom where department = ('HSD') GROUP BY (room_id) ORDER BY room_id";

	$click = mysqli_query($mysqli,$sql22);

	$click = mysqli_fetch_all($click,MYSQLI_ASSOC);

	$click = json_encode(array_column($click, 'count2'),JSON_NUMERIC_CHECK);
	
	
	
	$sql23 = "SELECT count(room_id) as count3 FROM mohconferenceroom where department = ('PLA') GROUP BY (room_id) ORDER BY room_id";

	$consult = mysqli_query($mysqli,$sql23);

	$consult = mysqli_fetch_all($consult,MYSQLI_ASSOC);

	$consult = json_encode(array_column($consult, 'count3'),JSON_NUMERIC_CHECK);

Open in new window


the chart library
<script>
$(function () { 

    var data_viewer = <?php echo $viewer; ?>;
    var data_click = <?php echo $click; ?>;
   var data_consult = <?php echo $consult; ?>;
	 
	 
 $('#ratiobetween').highcharts({

        chart: {

            type: 'column'

        },

        title: {

            text: 'conference room usage per department'

        },

        xAxis: {

            categories: ['room227','room327','room427']

        },

        yAxis: {

            title: {

                text: 'Rate'

            }

        },

        series: [{

            name: 'Administration',
            data: data_viewer
			
            

        }, {

            name: 'Health Services',

           data: data_click
		    
        },{
		 name: 'Planning',
		 
		  data: data_consult
		  
		}]

    });

});


</script>

Open in new window

Moses DwanaAsked:
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.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Why do you need 3 SELECTs? Can't you perform the query with a single SELECT? Like:
SELECT department, room_id, count(1) as count1 
FROM mohconferenceroom 
WHERE department IN ('ADM', 'HSD', 'PLA') 
GROUP BY department, room_id 
ORDER BY department, room_id;

Open in new window

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
Vitor MontalvãoMSSQL Senior EngineerCommented:
Only solution provided.
0
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
Databases

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.