close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Is JSON encode forcing strings instead of Integers?

Thread began 8/28/2018 7:50 pm by Steve | Last modified 8/29/2018 7:43 pm by Steve | 30 views | 5 replies

Steve

Is JSON encode forcing strings instead of Integers?

Hello,
I have this MySQLi query that returns results for a Charting application

php:
<?php

$LeadsChart 
= new WA_MySQLi_RS("LeadsChart",$high_i,0);
$LeadsChart->setQuery("SELECT CAST(SUM(MID)AS DECIMAL) AS y, CONCAT( LEFT(MONTHNAME(lddate), 3), ' ', YEAR(lddate)) AS label FROM tblleads WHERE mid = 1 AND lddate > 1 GROUP BY CONCAT( LEFT(MONTHNAME(lddate), 3), ' ', YEAR(lddate)), YEAR(lddate), MONTH(lddate) ORDER BY YEAR(lddate), MONTH(lddate) ASC");
$LeadsChart->execute();
?>



I've CAST the y value as UNSIGNED and DECIMAL but in each case the JSON Encode renders the result inside a double quote. This is preventing execution where actual numbers are needed to render the chart.

data: [
{
type: "spline",
dataPoints: <?php echo json_encode($LeadsChart ->Results); ?>
}
]



Result:

data: [
{
type: "spline",
dataPoints: [{"y":"29","label":"Jan 2016"},{"y":"24","label":"Feb 2016"},{"y":"40","label":"Mar 2016"},{"y":"32","label":"Apr 2016"},{"y":"28","label":"May 2016"},{"y":"38","label":"Jun 2016"},{"y":"37","label":"Jul 2016"},{"y":"29","label":"Aug 2016"},{"y":"21","label":"Sep 2016"},{"y":"22","label":"Oct 2016"},{"y":"16","label":"Nov 2016"},{"y":"15","label":"Dec 2016"},{"y":"19","label":"Jan 2017"},{"y":"29","label":"Feb 2017"},{"y":"33","label":"Mar 2017"},{"y":"28","label":"Apr 2017"},{"y":"23","label":"May 2017"},{"y":"27","label":"Jun 2017"},{"y":"27","label":"Jul 2017"},{"y":"20","label":"Aug 2017"},{"y":"31","label":"Sep 2017"},{"y":"26","label":"Oct 2017"},{"y":"27","label":"Nov 2017"},{"y":"14","label":"Dec 2017"},{"y":"22","label":"Jan 2018"},{"y":"26","label":"Feb 2018"},{"y":"31","label":"Mar 2018"},{"y":"28","label":"Apr 2018"},{"y":"2","label":"May 2018"},{"y":"17","label":"Jun 2018"},{"y":"41","label":"Jul 2018"},{"y":"20","label":"Aug 2018"}] }
]



Is there something in the way the Recordset Results are rendered that block or reassign the int as a string?

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...