Link to home
Start Free TrialLog in
Avatar of Jazzy 1012
Jazzy 1012

asked on

Json encode, change how it looks like on when inserting to database

I have this right now stored in my database:
deliver time:["Monday 5AM - 8AM"]date:["Monday, May 15th"]

Open in new window


How can I make it like this?
:
{"jsDate":"2017-05-15T05:00:00-08:00","dow":"1","string":"2017-05-15"}

Open in new window


I got the above by this, as you can see they are arrays:
$json_monday_time=json_encode($value1);
$json_tuesday_time=json_encode($value2);
$json_wednesday_time=json_encode($value3);
$json_thursday_time=json_encode($value4);
$json_friday_time=json_encode($value5);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jazzy 1012
Jazzy 1012

ASKER

Okay @ray your solution does work, now can can I do it dynamically for every data that I get like this
deliver time:["Monday 5AM - 8AM"]date:["Monday, May 15th"]

Open in new window

To turn into the new way I need it. Also if it is tuesday for "dow" : to be 2 and if its wednesday dow is 3 and so on
Let me try this again...
Can you please post the contents of $value1 and $value2 that are dependencies in the 3rd code snippet?
Okay also how can I add this to the json? ,"timezone":"Eastern Time (US \\u0026 Canada) to be written exactly like this inside the { }
$value1 would be Monday 5AM-8AM or (anytime that is chosen) $value2 = Tuesday 5AM-8AM or anytime that is chosen and tc with the values..
Jasmine, please do it this way.  Use PHP var_dump() to print out the exact and complete contents of $value1 and $value2.  Then use your browser's "view source" feature, copy the information from var_dump() and post it in the code snippet here.  Thanks.
$json_monday_time=json_encode($value1);
$json_tuesday_time=json_encode($value2);
$json_wednesday_time=json_encode($value3);
$json_thursday_time=json_encode($value4);
$json_friday_time=json_encode($value5);

var_dump($value1, $value2);

Open in new window


Also, have you tried using the other days in the script I posted?  What output did you get?
I get Success, but how can I add ,"timezone":"Eastern Time (US \\u0026 Canada) to the json?
You don't add to the JSON; you add to the object  that is used to make the JSON.

I will show you exactly how to do this as soon as you post the information I keep asking for!

var_dump($value1, $value2);

I get
Monday 5AM- 8AM
exactly like this
and $value2 is empty.
Jasmine, please!  Just copy the output from var_dump() and post it in the code snippet.  Do not describe it to me.  Do not post a picture of it.  Use the view source feature, copy the output of var_dump() exactly as it appears in the view source, and post it here in the code snippet.  This should be easy, but it's made difficult if you won't work with us here!

Here is an example of what I would expect to see based on the description you posted here.
string(15) "Monday 5AM- 8AM"
string(0) ""

Open in new window

array(1) { [0]=> string(16) "Monday 5AM - 8AM" } NULL array(1) { [0]=> string(20) "Wednesday 9AM - 12PM" } NULL NULL

I did value1, value2, value3, value4, value5
Now we may be making some progress!  Here is what I can discern from your post.
$value1 = [ 0 => "Monday 5AM - 8AM" ];
$value2 = NULL;
$value3 = [ 0 => "Wednesday 9AM - 12PM" ];
$value4 = NULL;
$value5 = NULL;

Open in new window

As you can see, it's not the same as the same as the earlier post, that said this.
deliver time:["Monday 5AM - 8AM"]date:["Monday, May 15th"]

Open in new window

So in order to get something like this, we would need to know how we decide that $value1 is the 15th of May, and not (for example) the 23rd of April.  How would we know that?
because of another variable I echo out with it
$value6 = "Monday, May 15th
$tuesday_time = ""Tuesday, May 16th" and so on
I'm sorry, Jasmine.  I can't keep wasting your precious time.  Recommend that you get professional help, maybe from Gigs.  Best of luck with your project.
This actually solved my issue I just had to add a few things, thank you so much! sorry for the inconvenience.