MySQL Archives

Create a Basic Web Service Using PHP, MySQL, XML, and JSON

Published by David Walsh on Wednesday, May 6, 200935 Comments

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.

Backup Your Database into an XML File Using PHP

Published by David Walsh on Friday, February 27, 200927 Comments

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

Published by David Walsh on Thursday, January 29, 200957 Comments

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

Published by David Walsh on Wednesday, November 19, 200838 Comments

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

Published by David Walsh on Friday, November 14, 200859 Comments

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

idtitlesort_order
1Article 11




© David Walsh 2007-2010. Contact David Walsh. Powered by the remarkable MooTools javascript framework.