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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:01:11+00:00 2026-05-30T19:01:11+00:00

I just want to know how can I add the data type here? Google

  • 0

I just want to know how can I add the data type here? Google Charts requires data type when I use this code:

Im getting an error from google charts that it datatype needs to be defined…please help. Thanks!

while($r = mysql_fetch_assoc($query)) {

     $google_JSON = "{cols: [";    
     $column = array_keys($r);
     foreach($column as $key=>$value){
         $google_JSON_cols[]="{id: '".$key."', label: '".$value."'}";
     }    
     $google_JSON .= implode(",",$google_JSON_cols)."],rows: [";       

   $google_JSON_rows[] = "{c:[{v: '".$r['id']."'}, {v: ".$r['count']."}]}";
}    
// you may need to change the above into a function that loops through rows, with $r['id'] etc, referring to the fields you want to inject..
//pass it into google charts data
echo $google_JSON.implode(",",$google_JSON_rows)."]}";
  • 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-05-30T19:01:12+00:00Added an answer on May 30, 2026 at 7:01 pm

    I haven’t done any PHP in ages so I’m not going to offer to provide any patches to your code but the data type goes in the array elements of the cols hash reference i.e., where you create {id:”key”, label: “value”} you need to add ‘type: “number”‘ or ‘type: “string”‘ etc. How you determine whether it is a number of a string by referring back to your query is not going to be that simple. You could look at the column type via whatever metadata the mysql module provides for the column but most charts require number types for the series and string/number types for the x-axis values. You could always set the first column to string or number and the other columns to number but it would depend on the sort of chart you are creating.

    BTW, I’m surprised you cannot create the structure natively in PHP and then convert to JSON rather than building the JSON string up like this – you can in Perl quite easily.

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

Sidebar

Related Questions

I just want to know: How can I delete 'log.txt' if the last modification
I just want to know if there is a program that can convert an
Just out of curiosity: I know I can tell the compiler if I want
i just want to know a general information about this particular information. Any good
I just want to know where am i wrong here: import java.io.*; class Tokens{
Just want to know if there other optional wrapper framework available that generate client
Just want to know how to read an attribute of a parent node from
I just want to know how does the table resulting from readXML look like,
i just want to know about the files and folder structure for a site
i just want to know how the call hierarchy is implemented in eclipse IDE

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.