Web Developing

I love being a web developer! Today’s project involved a bit of PHP, MySQL, JSON and WordPress–and Stack Overflow, of course 🙂

The Situation: I wanted to make a random quote appear on my WordPress site.

The Task: To make the random quote appear, I had to reconsider something similar I had developed for another web site. I needed to reformulate the process (because WordPress is different than the solution before).

Previous random quotation solution.

The Action: To save time, I decided that I didn’t need to reinvent the wheel: first I looked for WordPress plugins that could display information from tables. I downloaded and installed a few to try them out, and ultimately found a WordPress plugin from SriniG called “Quotes Collection” that allowed random quotations to be displayed as JSON objects. However, this led to other issues as my information wasn’t organized in a recognizable format.

I had to learn whether MySQL tables could be exported to JSON objects, and luckily, a website had everything I needed (it was literally called “How to Convert Data from MySQL to JSON using PHP“). So I built a simple web interface with HTML and PHP to execute the functions and, once I got that working, I specified the type of information I wanted to process.

The Quotes Collection WordPress plugin needed the data organized in a certain way, so I had to experiment with SQL statements to output the data correctly (for example, in my storage solution, I had an author’s first name and last name listed as separate items, whereas the WordPress plugin needed just a single entry for “Author’s Name”).

The SQL script to isolate only quotations and their authors.

Finally, I outputted the necessary information in a format that worked, and voila–the Quotes Collection is filled!

The quotations, now available for display!

The Result:

From this–

 

–to this!

Success! (Thanks SCC)