Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8744101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:47:30+00:00 2026-06-13T11:47:30+00:00

Could not convert or access JSON object from PHP json_encode <?php $f_array = array();

  • 0

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..

enter image description here

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:47:31+00:00Added an answer on June 13, 2026 at 11:47 am
    var j_array = <?php echo $j_array; ?>;
    

    Without ” “

    When you put the brackets you escape the json_encoded array at your javascript..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert a string to a JSON object that gets returned from
In my web app I have an object which is built from a JSON
Is there a way to easily specify whether to convert an object as JSON
Could not load file or assembly 'EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its
I could not integrate the Test Flight sdk in my ios App for crash
I could not figure out how to get the white fill for this ggplot2
I could not find a way to make a RTL paragraph in Docx using
I could not find the function that returns the name of the cell referenced.
I could not find a clear answer to this question elsewhere, so I'll try
I could not understand this error, the scenario is: This is the directory structure:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.