Admittedly, my understanding of arrays is junior at best (although before this I thought I had them figured out).
Essentially, I am trying to convert a PHP array to a JS array. The purpose for this is that ultimately I'd like to create a graph/chart using jquery (I've tried using php charts, but they haven't worked for me to this point).
Long story short, every time I try and convert my PHP array to a JS array, the output is "null". This may be due to my understanding of arrays...
//this query gets me the count of each type of variabletype
$sql = "SELECT variabletype, COUNT(variabletype) AS value_occurrence FROM variable GROUP BY variabletype ORDER BY value_occurrence DESC";
$vars_query = mysqli_query($con,$sql) or die(mysqli_error($con));
while($vars = mysqli_fetch_array($vars_query, MYSQLI_ASSOC))
{
//this is a sub-query that gets me how many of those records are considered "positive"
$times_positive_qry = mysqli_query($con, "SELECT variable.variabletype, COUNT(value.valueid) AS positive_occurrence FROM variable INNER JOIN value On variable.variableid=value.variableid WHERE variable.variabletype = '" .$vars['variabletype']. "' AND value.valuelift>0.00 AND value.valuesignificant=1 GROUP BY variable.variabletype ORDER BY positive_occurrence DESC");
$times_positive = mysqli_fetch_array($times_positive_qry, MYSQLI_ASSOC);
$pos = $times_positive['positive_occurrence'];
}
//this is the code that is supposed to take my php array and turn it into JS array.
echo "<script type='text/javascript'>";
$php_array = $pos;
$js_array = json_encode($php_array);
echo "var javascript_array = ". $js_array . ";\n";
echo "</script>";
Again, my understanding of arrays are junior, but I think it may have to do with my use of $pos. Is this not an array? or am I missing the mark somewhere else?
Any help would be much appreciated!
var_dumpon$posand see what the type is. That'll answer your question why it's returning null fromjson_encodewhileloop assigns a scalar value to$pos, so it's definitely not an array. and i'd bet the code is not executed at all (mysqli_fetch_array($vars_query, ...)returns no rows), so$posis not defined, and you've shot yourself in the foot with insufficienterror_reporting.