Web services are taking over the world. I credit Twitter’s epic rise to the availability of a simple but rich API. Why not use the same model for your own sites? Here’s how to create a basic web service that provides an XML or JSON response using some PHP and MySQL.
MySQL Archives
Create a Basic Web Service Using PHP, MySQL, XML, and JSON
Backup Your Database into an XML File Using PHP
Backing up data is extremely important. Most of the time the database is the most important piece of the puzzle. Imagine losing all of the data in your database — it would be tragic. Here’s a PHP snippet that outputs your database as XML.
Animated Ajax Record Deletion Using MooTools
I’m a huge fan of WordPress’ method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here’s how to achieve that functionality with MooTools javascript.
The PHP – Content & Header
The following snippet goes at the top of the page:
if(isset($_GET['delete']))
{
$query = 'DELETE FROM my_table WHERE item_id = '.(int)$_GET['delete'];
$result = mysql_query($query,$link);
}
The following is used to display the records:
Breaking & Fixing Dates from MySQL to PHP
The way that databases store “date” field data is:
2008-11-19 // year - month - day
The way that us humans read dates (at least in the U.S.) is:
11-19-2008 // month - day - year
I write a lot of administrative panel modules that either display dates or, better yet, allow customers to their own dates for articles, events, etc. I’ve created a couple of PHP functions that allow me to easily handle the transition from MySQL to PHP and visa versa.
Using MooTools 1.2 For Drag, Drop, Sort, Save
The following is a repost of an article that ran on Script & Style a few months ago….
My customers love being able to control their website’s content so I build a lot of administrative control into their website. One administrative control I frequently build is a News control. I allow the customer to add, edit, delete, and sort news items. My customers especially love sorting their articles because of the fashion of which they can sort: drag and drop. Here’s how I do it.
The MySQL Table
| id | title | sort_order |
|---|---|---|
| 1 | Article 1 | 1 |