Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you are quite a bit confused. Lets take it step by step.</p> <p>First, <code>implode</code> concatenates the values of the array, not the keys, so it's logical you get that output, it's not "for some reason". Read <a href="http://php.net/manual/en/function.implode.php" rel="nofollow">the docs</a> about that function, is very helpful to know what it does.</p> <p>Second... well, from what I see, you're trying to mix php variables with js. It's "possible", but you need to really understand what you're doing. Google Charts or Highcharts construct graphs with js, at least based on the output you want to have. It's weird that you're imploding a variable in the controller and print it <em>just like that</em> in the view.</p> <p>So, pass the <code>$records</code> variable to the view as is. Do not try to transform it to an js-adequate-structure in the controller. Why? Because you can use <code>$records</code> in any part of your view (as a php variable), and output the necessary structure just in the js part.</p> <p>Now, the graph. Let's say you're using Google charts because that's the first example I found. Somewhere in your view, you should have something similar to this</p> <pre><code>&lt;script type="text/javascript"&gt; //definitions of your chart, I'm not going to do that here //the data part var data = new google.visualization.DataTable(); data.addRows([ ['Mushrooms', 3], ['Onions', 1], ['Olives', 1], ]); </code></pre> <p>That's the data you want to "translate" from php-find-variable to js, right? For that you can do something like this</p> <pre><code> //the data part var data = new google.visualization.DataTable(); data.addRows([ &lt;?php foreach($records as $compound =&gt; $sum) echo "['".$compound."', ".$sum."], "; ?&gt; ]); </code></pre> <p>And you should have the js format you need. Check the syntax, though, I didn't test it so maybe there's a comma or something you need to add to that <code>echo</code>.</p> <p>I hope I made it clear enough. If you're confuse about anything here, I recommend to read about using php variables in js.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload