close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

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 Ray Borduin | 74 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?

Sign in to reply to this post

Ray BorduinWebAssist

It might be the recordset doing that. Can I get FTP access to the page? I can debug it. Depending on the php version it actually uses 1 of 3 functions to get the results. One or more may convert to strings... If I could debug your page I could narrow down which function yours uses and perhaps find a solution.

Sign in to reply to this post

Steve

PHP 5.6.31

FTP credentials provided.
I may need create a dup page removed from the login requirements... Let me look at that to assist
Isolated test page:
http://isemanhomes.com/Admin/webassist-chart.php

Sign in to reply to this post

Ray BorduinWebAssist

It appears that FTP account doesn't have write access, so I can't update the files to debug them. I'll need more permissions in order to debug the problem and find a solution.

Sign in to reply to this post

Steve

Sorry Ray,
PERMISSIONS CHANGED

A solution is not needed unless you want to find out why the json is acting as it is.
I've moved to the Google Charts methods. (http://isemanhomes.com/Admin/chart-google.php)

Sign in to reply to this post

Ray BorduinWebAssist

I found a solution. I'll be updating the connection file to account for this in the next build.

Sign in to reply to this post

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