addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Seattle PHP User Group Message Board › Json and PHP

Json and PHP

Karim R.
nosql
Austin, TX
Post #: 1
I have an array
{
[Title, 4,5],
[month: 4],
[X,30843],[Y,33954],[Z,23896][Y,59840]­,
[month: 5],
[X,17529],[Y,19259],[Z,12880][Y,33402]­
}

it's a result of sql query,
I don't know if it's an array or not.

and I want to parse it to look like :
['Title', '4', '5'],
['X', 30843, 17529],
['Y ', 33954., 19259],
['Z', 23896, 12880],
['Y', 59840, 33402]


I'm using PHP, and Javascript
I want to use this result to feed it to a Barchart, google API.

Does any one have any idea how to do that, will be really appreciate it !!

Thanks in advance!

-Karim
Jd D.
ehime
Seattle, WA
Post #: 2
Neither of those are correct JSON to my knowledge, and the
issue I immediately see is that you will be overwriting the Y
value due to the second declaration....

['Title', '4', '5'],
['X', 30843, 17529],
['Y ', 33954., 19259],
['Z', 23896, 12880],
['Y', 59840, 33402]


Do mind showing me how you're querying in order to get this returned?

.... EDIT

I think the proper array / json encode would look something like this (notice the y^2 or y2 or whatever you want to call it, this prevents overriding the y parameter ;) )


$etc = array(
'title' => array(4,5),
'month' => array(
4 => array(
'X' => 30843,
'Y' => 33954,
'Z' => 23896,
'Y^2' => 59840,
),
5 => array(
'X' => 17529,
'Y' => 19259,
'Z' => 12880,
'Y^2' => 33402,
),

),

);


echo json_encode($etc);
// result: {"title":[4,5],"month"­:{"4":{"X":30843,"­Y":33954,"Z":23896,"­Y^2":59840},"5":{"X"­:17529,"Y":19259,"Z"­:12880,"Y^2":33402}}}

Powered by mvnForum

Our Sponsors

  • PluralSight

    PluralSight subscriptions for developer training

  • O'Reilly

    Disc Code: PCBW is good for 40% off print and 50% off ebooks and videos

  • JetBrains PhpStorm

    Occasional free licenses to raffle off at meetups

  • DynaTrace

    Find yourself, promote yourself, stay true to yourself.

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy