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

  • SEARCH
  • Home
  • 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 7878323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:37:36+00:00 2026-06-03T03:37:36+00:00

I am trying to get my JSON encoded array formatted properly. Here is my

  • 0

I am trying to get my JSON encoded array formatted properly. Here is my PHP MySQL Query:

$query = "SELECT date, value1, value2
            FROM testdata
            ORDER BY date ASC";  


         $result = mysql_query($query);
         $myChartData = array();
          while($row = mysql_fetch_assoc($result)){
            $myChartData[] = $row;
                        }

   <script type="text/javascript">
    var chartData = <?php echo json_encode($myChartData); ?>;

From the console, the object looks like this:

[Object { date="2011-02-23", value1="133034", value2="12105.78"},
 Object { date="2011-02-24", value1="122290", value2="12068.50"},
 Object { date="2011-03-08", value1="453142", value2="12214.38"}]

The quotation marks around the date stays, but the ones on value1 and value2 need to be stripped out.

Self-teaching noob at all of this…Thanks for your help!

  • 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-03T03:37:38+00:00Added an answer on June 3, 2026 at 3:37 am

    A simple javascript solution:

    function formatChartData(data) {
        for(var i = 0, length = data.length; i < length; i++) {
            data[i].value1 = parseInt(data[i].value1, 10);
            data[i].value2 = parseFloat(data[i].value2);
        }
        return data;
    }
    
    var chartData = formatChartData(<?php echo json_encode($myChartData); ?>);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Javascript. I'm trying to loop through an array encoded with JSON. Here is
I was trying to get away from using PHP's htmlentities and here's where I
i have a json data retrieved from data base i.e $result=array(); $query=SELECT * FROM
I trying to build a JavaScript function which will grab a JSON encoded array
I'm trying to post the lang_id var. to get_lang.php with jquery to get (json)
I am trying to json encode an array,it does encode but i get lots
I'm trying to get a PHP array with AJAX and turn it into a
Trying to get a JSON output to work with jqGrid 'userdata' option. The example
While trying to GET a JSON, my callback function is NOT firing. $.ajax({ type:GET,
I'm trying to get some json data in my application, but it won't come

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.