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 8541145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:45:51+00:00 2026-06-11T11:45:51+00:00

I have a database of website stat which recorded a user view. I’d like

  • 0

I have a database of website stat which recorded a user view. I’d like to read and export into JSON. I can do it but I’d like to re-write them into a given format. What should I do?

Expected JSON code: //originated from http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?

callback(/* AAPL historical OHLC data from the Google Finance API */
[
/* Sep 2005 */
[1127088000000,52.64],
[1127174400000,53.19],
[1127260800000,52.11],
[1127347200000,51.90],
[1127433600000,53.20],
[1127692800000,53.84],
[1127779200000,53.44],
[1127865600000,51.08],
[1127952000000,52.34],
[1128038400000,53.61],
...
]);

Here is my code:

$sql_viewer="select sum(vwr_id) as num,vwr_date from car_viewer where vwr_tid='$_tid' group by year(vwr_date) desc, month(vwr_date) desc";
$result_viewer=mysql_db_query($dbname,$sql_viewer);
while($rec_viewer=mysql_fetch_array($result_viewer)){
    $_viewerDate=$rec_viewer['vwr_date'];
    $_viewerNum=$rec_viewer['num'];
    foreach($rec_viewer as $key=>$val){
        $arr[$key]=$val;
    }
    $main_arr[]=$arr;
}
echo json_encode($main_arr);

Result JSON:

[{"0":"221944676","num":"221944676","1":"2012-09-01 00:20:08","vwr_date":"2012-09-01 00:20:08"},{"0":"66772926","num":"66772926","1":"2012-08-09 23:35:04","vwr_date":"2012-08-09 23:35:04"},{"0":"609","num":"609","1":"2012-02-20 22:40:29","vwr_date":"2012-02-20 22:40:29"}]

The question is how can I re-write the result JSON into the expected format above?
Regards,

  • 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-11T11:45:52+00:00Added an answer on June 11, 2026 at 11:45 am

    The problem with your code is that the inner arrays had both numeric and integer indexes.

    $sql_viewer="select sum(vwr_id) as num,vwr_date from car_viewer where vwr_tid='$_tid' group by year(vwr_date) desc, month(vwr_date) desc";
    $result_viewer=mysql_db_query($dbname,$sql_viewer);
    while($rec_viewer=mysql_fetch_array($result_viewer)){
        $_viewerDate=$rec_viewer['vwr_date'];
        $_viewerNum= intval ( $rec_viewer['num'] );
        // Create an array with just integer indexes
        $main_arr[]=array(strtotime($_viewerDate) * 1000, $_viewerNum);
    }
    
    echo 'callback(' . json_encode($main_arr) . ');';
    

    , the code above makes the inner array have only integer indexes

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

Sidebar

Related Questions

I have a database for a forum-like website. It has a 'users' table, which
I have a database server which collect user&pass of users (by login from website).
Currently I have a website and database solution, however I would like to take
I'm currently writing a website in ASP.NET MVC, and my database (which doesn't have
I have local database driven website which contains a few sequences which are uniquely
I'm developing a website/database solution which gives the administrator the option to sign into
In my website i have a database intensive page which i cache for 5
I have a database which has form authentication tables for an website [let say
I have a database menu structure which I would like to add to the
i have a database table of website links. i have another table of tags,

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.