Could not convert or access JSON object from PHP json_encode
<?php
$f_array = array(); // ---- Custom Line 1
for ($i=0; $i < $interval; ++$i)
{
$t_date = date('Y-m-d', strtotime($k_date1 . "+ $i day"));
$f_array = array();
$f_query = mysql_query("select COUNT(j.job_id) as `job_count`
from jobs j
where j.job_posted_date
LIKE '%$t_date%' and j.job_status = 3");
if (mysql_num_rows($f_query) > 0)
{
$f_query_data = mysql_fetch_array($f_query);
$f_count = $f_query_data['job_count'];
$f_array = array_push($f_array, $f_count); // ---- Custom Line 2
// $f_array[] = $f_count; // ---- Custom Line 3
}
}
$j_array = json_encode($f_array);
?>
I get only one value ie 1
in Javascript, with enabling
Custom Line 1
& Custom Line 2
.
And when i enabled
Custom Line 3
and disable Custom Line 1
& Custom Line 2
. then i get output good as in from database
<script>
var j_array = "<?php echo $j_array; ?>";
</script>
Result 1
<script>
var j_array = "1";
</script>
Result 2
<script>
var j_array = "["0","0","0","2","0","0","0","0","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","25","0","0","0","0","0","7","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1","0","0","1","1","47","0","1","1","0","0","0","0","0","0","3","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]";
</script>
And i have attached an image below..
Now how can i access the Result 2
in an order of an Array
or any other method.
And i tried using below
<script>
alert(j_array);
</script>
<script>
alert(j_array.0); // as an Object mightbe .. or I dont have any idea on it, so experimenting ..
</script>
What i need or Need Help
Its not giving any result as 0
is a integer
not string
.. And if its an Array
then its also tricky.. there are n
number of String 0
.. so how can i call one by one. or To convert into Javascript array.
Note: Result 2
is desired output, but its not in Array