By Jordie Bodlay
Being healthy is the "new" thing around the office at Interspire. Rodney and I have taken up the challenge of Mitch and Ed and have been keeping to a strict routine of exercise and a healthy diet.
Instead of scouring the local take-aways for lunch everyday, we now pop on down to the supermarket to buy fresh produce and meats to make our own lunches. However, we always found ourselves in a situation where we would forget something. Sure we could be old fashion and make a list and put it on the office fridge, but then I asked myself, "why do that when I could whip up an online shopping list?"
Our list became a hot little item around the office, so I thought I'd spend an hour explaing how you too can build your very own shopping list with. Keep in mind that you don't have to use this just as a shopping list – it can also be a To-Do list or practically a list of anything you need to remember.
In this article I do assume you have a small amount of PHP and MySQL experience, so if you don't then you might have to stick to a written shopping list for now.
![]()

Let's get busy!
First up we're going to create the MySQL database table. Here is the schema for the table we are going to use.
CREATE TABLE `thelist` (
We have 6 fields in 1 table for this script.
Now that we've setup the database we will set up our PHP script. To make it easy we'll keep everything in one file – unlike how we code our applications, mind you ;)
Let's start off with the database connection:
<?php
So far, so good. This code makes sure we're connected to the database. Once that's done we can do what we want with the table.
Continuing on from there we are going to use a switch statement to select what action to take. We have all of our actions inside separate functions so that the code is easy to maintain and update at a later time. (this code follows on from above)
<?php
The functions are pretty self explanatory so I wont go into too much detail. You can download the shopping list script here to try it yourself. Just make sure you create the database table before running the script or you'll receive a nasty error!
|
said this on 31 Jan 2007 4:26:37 PM CST
Great little script can wait to try it.
Thank you |
|
said this on 13 Aug 2008 5:17:53 PM CST
Nice base script. Easy to expand to something with more features. There are a few errors in the script. the link for edit goes to action=edititem when it should be action=edit, nothing too hard to change. Also depending on your version of MySql you may have to change the SQL queries. Over all a nicely coded script. Thank you
|
|
said this on 12 May 2009 6:43:32 AM CST
Thanks for sharing. Made it easy when someone had done all the heaving lifting. Would be nice to get a version posted without the SQL or URL bug. I've already added the ability to toggle the Purchased? option with a link.
Thanks very much |