Posts

Showing posts with the label JSON data format

How to use JSON, jQuery and mySQL in PHP

Image
Today, I dabbled for the first time with PHP, JSON, jQuery and mySQL. I am writing this post for my own reference as well as hoping that it will be useful for others who are trying to do something similar as I was. If you are too lazy to try out the code yourself, you can access this page to see a demo of what this code does . The code snippets provided below will help you to accomplish these tasks: Fetch data from a mySQL database and convert it to JSON data (demo_mysqltojson.php) Invoke an AJAX call to the PHP script above upon a button click using jQuery that returns JSON data, read and convert the JSON data to array-like records that can be iterated and used. (demo_showjsondata.php) Create a JSON array and send that JSON array via an AJAX call to a PHP script (demo_jsontomysql.php) that will add it to a mySQL database demo_mysqltojson.php <? $con = mysql_connect("localhost","demouser","demopassword"); if (!$con) { die('Could not ...