Data serialized by PHP should be deserialized by PHP, since it is a format proper to that environment. It would be unwise to use a JavaScript deserialize function when you have the possibility to do that in PHP itself. ![]() JSON API Serializer. A Node.js framework agnostic library for. Calling the serialize method on the returned object will serialize your data (object or array). So do this in PHP: // Deserialize your data $data11 = unserialize($row['data']); // JSON encode it, and output that echo json_encode($data11); Then in JavaScript, assuming you get the PHP data in a variable response (via an Ajax request): var data = JSON.parse(response); I suppose you already have the code to perform the Ajax request. If not, look at the many Q&A on that subject, for example. Assume we need to track your system means In your system has more than one admin and subadmin, All of these can insert or update or edit any information.Later you need to know who make this change. For solving this problem you need serialize. **Explain:**Create a table named history which stores all changes. Each time there is a change insert a new row in this table. It might have this fields: history(id,target_table(name of the table), target_id (ID of the saved entry),create/edit/change data (serialized data of the saved row),date) I hope this will help you. Basically, when you serialize arrays or objects you simply turn it to a valid string format so that you can easily store them outside of the php script. • Use serialize to save the state of an object in database (lets take the User class as an example) Next unserialize the data to load the previous state back to the object (methods are not serializer you need to include object class to be able to use it) • user personalization Note for object you should use magic __sleep and __wakeup methods. __sleep is called by serialize(). A sleep method will return an array of the values from the object that you want to persist. __wakeup is called by unserialize(). A wakeup method should take the unserialized values and initialize them in them in the object. For passing data between php and js you would use json_encode to turn php array to valid json format. Or other way round - use JSON.parese() to convert a output data (string) into valid json object. You would want to do that to make use of local storage. (offline data access). I've been working on some very large forms lately and I've come to the conclusion that creating a database scheme around them wouldn't be the best option because: • My customers don't need to analyze all form submissions as a whole -- form information is simply used on a per-submission basis (like a job application, for example). • Making updates to these forms would be very costly since it would take quite a bit of time to add and remove DB fields as well as update the HTML form. • I'd like to revert the information into an array format just like it came in easily. For that reason, I've been using the serialize() and unserialize() functions often. Serializing an array keeps the information in an array format, so to speak, but in one long string.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2018
Categories |