0

I have an external PHP include script that polls my database and results in an array that I json encode and parse on as a variable $final.

The last line of that code is $final = json_encode($dataset1,JSON_NUMERIC_CHECK);

The echoed output of that looks like [[1,7],[2,10],[3,10]].

I am using this data to populate a dynamic Ajax Flot line plot showing listeners on my radio station at one minute intervals.

However, and here is my question... I also want to display a single integer value on my web page, for the last item (y value) in the array. For the example above 10. e.g. Number of listeners: 10

Furthermore I would like to use the Ajax sweep, which updates the array to dynamically update this integer.

For further context, including the ajax here is the code that results in the array, and ajax updated chart.

I only include this because I want to make use of the Ajax/Variables already being used.

Community
  • 1
  • 1
square_eyes
  • 1,269
  • 3
  • 22
  • 52
  • What is your problem? What code did you try that failed? It seems to be quite trivial: `JSON.parse(response).pop().pop()` – Bergi Oct 21 '13 at 16:59
  • I tried `` But I don't know how to get the array into the javascript. Or echo it out to my page. And it didn't work anyway. – square_eyes Oct 21 '13 at 17:02
  • Where did that `json[` come from? Why are you using `keys` and why do you sort them? What about that `?>`? It should be `var highest = echo $final; ?>; var ten = highest.pop().pop();` – Bergi Oct 21 '13 at 17:08
  • json came from another example I found on here. So did the sorting. the ?> is a typo I'll remove it. – square_eyes Oct 21 '13 at 17:11
  • [Here](http://jsfiddle.net/nDYjV/) is a jsfiddle – square_eyes Oct 21 '13 at 17:14
  • 1
    That looks good apart from the fact that JSfiddle does not execute PHP… – Bergi Oct 21 '13 at 17:27
  • OK great, so how do I echo the output to may page, then use an existing Ajax loop to push the updated value to the echo? – square_eyes Oct 21 '13 at 17:29
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/39669/discussion-between-square-eyes-and-bergi) – square_eyes Oct 21 '13 at 17:29
  • All working now if you want to answer the question. – square_eyes Oct 22 '13 at 13:24

0 Answers0