JSON / PHP / SQL / Google Charts question

JSON / PHP / SQL / Google Charts question

by Mike Glazebrook -
Number of replies: 3

I have been working on this a long time and also am a bit of a novice when it come to sql and making it talk to these charts. 

what I have is this (see screenshot). The JSON that I have generated is as follows:

{"cols":[{"label":"firstname","type":"string"},{"label":"mike","type":"number"},{"label":"alex","type":"number"},{"label":"tommy","type":"number"}],"rows":[{"c":[{"v":"9 October 2013, 3:53 PM"},{"v":2}]},{"c":[{"v":"10 October 2013, 2:08 PM"},{"v":3}]},{"c":[{"v":"11 October 2013, 10:07 AM"},{"v":5}]},{"c":[{"v":"14 October 2013, 3:56 PM"},{"v":5}]},{"c":[{"v":"14 October 2013, 3:58 PM"},{"v":3}]}]}

I need to  figure out how to A generate the firstnames from the database. Right now I have just hand coded them in. I tried using a foreach such as the rows are generated but it returned an error saying invalid column label:firstname. I have aslo attached my php and html that are making this work.

I know how the json needs to look I just dont know how to make it look that way. Here is how it needs to look:

{"cols":[{"label":"firstname","type":"string"},{"label":"mike","type":"number"},{"label":"alex","type":"number"},{"label":"tommy","type":"number"}],"rows":[{"c":[{"v":"9 October 2013, 3:53 PM"},{"v":4.4},{"v":4.3},{"v":3.1},{"v":4.3}]},{"c":[{"v":"10 October 2013, 2:08 PM"},{"v":4.4},{"v":4.3},{"v":3.1},{"v":4.3}]},{"c":[{"v":"11 October 2013, 10:07 AM"},{"v":4.4},{"v":4.3},{"v":3.1},{"v":4.3}]} etc...

you can see the change that there are multiple values per person now. Those are all the 'rank' values. The current values are actually associated with different people. so I would need the names in the columns to match up with the date and the 'rank' values associated with that person. 

I think I am close I just need a little help. Does anyone know how to do this?

Thanks,

Mike

Attachment Screen Shot 2013-10-15 at 12.26.14 PM.png
Average of ratings: -
In reply to Mike Glazebrook

Re: JSON / PHP / SQL / Google Charts question

by Mike Glazebrook -

thought I would write an update that will hopefully help us both out here. I have gotten the JSON to look as such:

{"cols":[{"label":"Alex","type":"string"},{"label":"mike","type":"string"},{"label":"Super","type":"string"},{"label":"test","type":"string"}],"rows":[{"c":[{"v":2}]},{"c":[{"v":3}]},{"c":[{"v":5}]},{"c":[{"v":5}]},{"c":[{"v":3}]}]}

I am getting this error: 

 
Invalid column label:firstname

I will reattach my php and html. I think I just need help writing the php a bit. I don't know why the error is showing for firstname as that part of the JSON looks good to me. It would be very helpful if someone could help me get all the 'rank' values {"c":[{"v":5}]} to show up all for each person. So one person may look like this {"c":[{"v":4.4},{"v":4.3},{"v":3.1},{"v":4.3}]} and etc. right now because of the foreach it is only displaying one value per instance of the persons answer. 

Thanks in advance.

 

 

In reply to Mike Glazebrook

Re: JSON / PHP / SQL / Google Charts question

by Nicolas Martignoni -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Mike,

It seems to me that your question doesn't have anything to do with Moodle. Are you aware that this forum is intended to address support in development in Moodle?

I'm sure you'll get more help if you ask at the correct place. My suggestion: JSON and/or PHP forum?

Good luck,

Nicolas

In reply to Nicolas Martignoni

Re: JSON / PHP / SQL / Google Charts question

by Mike Glazebrook -

Hi Nicolas,

Thanks for the response. Also you make a good point. I am using these charts with moodle but this question has nothing to do with moodle. I will try a different forum. Sorry for posting in the wrong place.