Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


PHP and MySQL examples

 

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.

 


 

 

Examples

Display all of the available links in the database
Display x amount of links
Randomizing the output displayed
Displaying one random link from the database
Display the fields alphabetically
Counting the amount of rows in the database
Displaying results from only one category in the database
Display a different result depending on the week day.
 
 



 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
add a site to IE favorites(VBScript)
a simple dialog box using swing(Java)
gethostbyaddr function(PHP)
display start menu programs(VBScript)
Check if network is available(VBnet)
Create a text file(Powershell)
vertical scrolling text(Blitzbasic)
set text colour(CSS)

    




Copyright © 2004 by programmershelp.co.uk