Storage of Json data to mysql database using php - javascript

I am doing a leapmotion webapp on PHP and javascript.it is based on gesture recognition. The values of the leapmotion must be stored into the database and when the corresponding gesture is matched the description of the gesture must be displayed. The values from the leapmotion is converted to JSON format. How can I store the JSON data to the mysql database 5.0.?
The JSON file content is:
{"name":"HA","pose":true,"data":[[{"x":0.16616291409773337,"y":-0.061424365133667,"z":-0.014198921561969446,"stroke":1},{"x":0.058005894163526694,"y":-0.05005164610312531,"z":0.029463953896938344,"stroke":1},{"x":-0.05015112577067998,"y":-0.03867892707258362,"z":0.07312682935584591,"stroke":1},{"x":-0.1583081457048866,"y":-0.02730620804204193,"z":0.1167897048147537,"stroke":1},{"x":-0.2664651656390933,"y":-0.01593348901150024,"z":0.16045258027366138,"stroke":1},{"x":-0.3746221855732999,"y":-0.00456076998095855,"z":0.20411545573256906,"stroke":1},{"x":0.6253778144267002,"y":0.19795540534387668,"z":-0.5697496025117985,"stroke":1}]]}
The error which i get is Syntax error. The work is based on Rob O'leary's leaptrainer.js which can be found on https://github.com/roboleary/LeapTrainer.js/tree/master.

In your situation I'd prefer to do next:
Create separate table for these data. Keys are dependable from your
purposes, but as quick solution just create table with the same
columns names as in your JSON.
Create some model, to communicate with DB. Make there some
methods(like saveMotion, getMotion etc.)
In your php code, use json_decode function, to convert JSON to std
object. Not sure here if you will be able to write std class to db,
but conversion it to array would give you a 100% possibility to do
that.

Related

How to retrieve 20,000 documents from firestore database using javascript

I am having a firestore database, where it having a collection named emails. In emails it is having thousands of documents with dynamically created DocumentId's but i need to retrieve the data from each & every document.
tried syntax :- db.collection("emails").get().then((snapshot) => {});
example:-
emails - 001H2rmjHGOE4joI9kZQ58e9ET93 - name,age,phoneNumber
00L9cjByEHPmzJpBfhSvuRaiKk42- name,age,phoneNumber
i need all the phoneNumbers from every document by using javascript.
a simple thing, create a bucket in your firebase console, next create a dataset and download the required data using SQL type console it provides JSON, CSV file formats follow below link for the full process.
https://www.youtube.com/watch?v=3J1M1bSwgV8&list=LL&index=14&t=3s

Format data served from MySql via PHP PDO to feed Googe Charts on the Visualization API

I need to generate decision trees from a MYSQL v 5.6 table, queried with PHP PDO. I have a nice query which gives the data required, however I can't find the correct format to parse data to the Google API.
I searched and found a myriad of articles on how to format data to feed Google Charts. However the common denominator is the use of the infamous and deprecated mysql_query class to fetch data, and some addrow method which I found quite strange and UnClean.
I'm asking how should I format the json output in order to porperly feed the API. At the moment I query the data, json encode it using PHP's json_encode, and get the data properly via AJAX. Indeed my console shows that the data is properly read by the browser, however I know there is a format issue.
Unfortuantely tha google visualization API doesn't give me info on where the error could be. I just received this message:
Invalid format in explicit format: column #0 must be of type 'number'
Well this is a sample of data that the google javascript receives:
[{"id":"1","elemento":"CLIO","parent":"0","size":306}, {"id":"2","elemento":"LOGAN","parent":"0","size":431}, {"id":"3","elemento":"SANDERO","parent":"0","size":335},
On the other way, I'm following strictly the Google visualization guidelines to use data from external data sources:
Populating Data Using Server-Side Code
and specifically the chart that I need to render Wordtrees, which uses and arrayToDataTable method to format properly the data.
What should I correct in order to get and/or read the proper formatted json string of data? Please keep in mind the previous example of actual data which uses:
echo json_encode($data);
to JSON format the query output. Should I construct a table? How to do it in a proper, clean and modern way, not the mysql_query iteration.
Thanks for your time and collaboration.

Laravel PHP - Custom JSON object from DB to PHP to JS to HTML

I have to create a custom json object (I need to decide what info goes where in what order) with data I get from PHP in my Controller.
As I see it, I think I need some roundtrips like this:
Get data from Laravel-form in my Controller (Input::get('name'))
Pass that data to JavaScript to build my JSON
Pass that JSON back to PHP
Convert this JSON to a string (to store it in Redis)
And when I try to read this data go the other way around:
Get data from DB
Pass data to JavaScript to get each element/node
Parse those values to html (to display the data from the json)
How would I pass variables from PHP to JS and back? Not sure how that works... A good explanation (with some code or example) would be much appreciated!!!
Or is there another 'better' way?
I am using Laravel 5.2 and NoSQL Redis. I need to create a somewhat complex JSON that looks like this and store that in Redis. This JSON will never be more than twice the size of this one shown here.
Thanks
to generate json data, you can do that with json_encode function in php. No need to pass to javascript to build json data.
http://php.net/manual/en/function.json-encode.php
update:
you can store the response of json_encode function in a variable and you can do whatever you want with that variable
$json_data=json_encode($data);

How to retrieve images from database using jquery and servlet

I need to retrieve the images which is stored in my oracle 11g R2 database. I'm trying to retrive the images using Jquery and servlet, And placing into the css division. But I'm a newbie in this. I know using json objects we can do this stuff. Please anyone tell me how to do
Make a request that returns a list of the names of all images (so that you know what to retrieve)
Make a servlet that serves images - gets the name as GET parameter, looks it up in the database (e.g. via JDBC) and streams the result back into the response.getOutputStream(), and set the correct content type

How to store a multi-dimensional javascript array in a mysql database

I have a javascript application that's will keep track of the x&y coordinates of several objects on a 'canvas.' I'm planning on storing this data in a 2-dimensional array such as:
new Array(
new Array(id0, x0, y0),
new Array(id1, x1, y1),
new Array(id2, x2, y2));
I want to submit this data to a php script and store it in a mysql database for later retrieval/redisplay. What's a good way to do this? Should I serialize the array and encode it for transport? I'm using jQuery so if anyone knows of any good functions included in this framework that would be great. Thanks!
Serialize your array to a storable format (usually string), send it to the server that will store it to the DB.
You might use JSON, XML or any other format. I'd go for JSON as it's less verbose, then using less space in your database.
However be aware that serializing arrays prevent any querying using the database engine. You will have to extract your data, unserialize it, check if it's the one you need, and rinse and repeat until you found the right array (unless you know the ID of the array you're looking for).
NB: Don't forget to use POST request to send it to the server, as GET request have a length limit.
The best idea seems to be JSON.
Just encode your array in JSON, send it to the server. If you do not need to manipulate data on the server side, you can even save the JSON itself to MySQL. Otherwise, all wide-spread server-side languages have JSON handling functions (json_decode() and friends in PHP).
On the route back (from server to Javascript), JSON again is the simplest way. You can use jQuery's getJSON() or parseJSON() functions to handle it, and get your array.

Categories

Resources