| The purpose of the series of examples is to show how to manipulate data in a database using PHP and MySQL. Most of these are carried out using SQL statements but these are all common techniques which can be used with any database.
First of all we will show you a dump of the database, this will make it easier to create the database for yourselves.
First of all you have to create a database called test. Now here is the structure and some sample links.
# phpMyAdmin SQL Dump
# version 2.5.2
# http://www.phpmyadmin.net
#
# Host: localhost
# Generation Time: Feb 03, 2004 at 05:00 PM
# Server version: 4.0.15
# PHP Version: 4.2.3
#
# Database : `test`
#
# --------------------------------------------------------
#
# Table structure for table `test`
#
# Creation: Feb 03, 2004 at 04:36 PM
# Last update: Feb 03, 2004 at 04:44 PM
#
CREATE TABLE `test` (
`id` int(4) NOT NULL auto_increment,
`cat` varchar(10) NOT NULL default '',
`url` varchar(50) NOT NULL default '',
`name` varchar(50) NOT NULL default '',
`desc` varchar(100) NOT NULL default '',
KEY `id` (`id`)
) TYPE=MyISAM AUTO_INCREMENT=13 ;
#
# Dumping data for table `test`
#
INSERT INTO `test` VALUES (1, 'search', 'http://www.google.com', 'google', 'The best search engine and directory');
INSERT INTO `test` VALUES (2, 'search', 'http://www.monstersearch.co.uk', 'monster search', 'PPC search engine');
INSERT INTO `test` VALUES (3, 'shopping', 'http://www.clickstores.co.uk', 'click stores', 'A wide range of merchants');
INSERT INTO `test` VALUES (4, 'search', 'http://yahoo.com', 'yahoo', 'The mighty yahoo');
INSERT INTO `test` VALUES (5, 'program', 'http://www.programmershelp.co.uk', 'programmershelp', 'Various programming resources');
INSERT INTO `test` VALUES (6, 'program', 'http://asp.programmershelp.co.uk', 'Beginners ASP', 'Lots of ASP resources');
INSERT INTO `test` VALUES (7, 'program', 'http://www.beginnersphp.co.uk', 'Beginners PHP', 'Beginners PHP site');
INSERT INTO `test` VALUES (8, 'program', 'http://www.programmingsite.co.uk', 'programmingsite', 'programmingsite directory');
INSERT INTO `test` VALUES (9, 'misc', 'http://www.bigjokes.co.uk', 'big jokes', 'Lots of jokes');
INSERT INTO `test` VALUES (10, 'misc', 'http://www.cheatsnhints.com', 'cheatsnhints', 'cheats and hints');
INSERT INTO `test` VALUES (11, 'program', 'http://www.hirecoders.com', 'hire coders', 'Freelance programming site');
INSERT INTO `test` VALUES (12, 'misc', 'http://www.mywebhosting.co.uk', 'mywebhosting', 'Low cost hosting');
As you can see we have 12 links and 4 categories set up in this simple database. Lets look at some examples to see how to get the information we want out of the database.
|