|
First of all you have to create your MySQL database . To keep things simple I use PHPMyAdmin which offers a nice user friendly front end to MySQL . Create a database and call it anything you want , in this case maybe call it test.
Here is a SQL dump of the information that you require to add to your database
#
# Table structure for table `links`
#
# Creation: Aug 12, 2003 at 05:11 PM
# Last update: Aug 12, 2003 at 05:28 PM
#
CREATE TABLE `links` (
`id` int(10) unsigned NOT NULL auto_increment,
`url` varchar(100) NOT NULL default '',
`description` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;
#
# Dumping data for table `links`
#
INSERT INTO `links` VALUES (1, 'http://www.programmingsite.co.uk', 'programming directory');
INSERT INTO `links` VALUES (2, 'http://www.beginnersphp.co.uk', 'PHP tutorials and code');
INSERT INTO `links` VALUES (3, 'http://asp.programmershelp.co.uk', 'ASP site with code and tutorials');
INSERT INTO `links` VALUES (4, 'http://javascript.programmershelp.co.uk', ' javascript site');
INSERT INTO `links` VALUES (5, 'http://software.programmingsite.co.uk', ' software directory');
Now for the actual script itself , again you can call the script anything you want.
<?php
//connect to database using the mysql_connect function()
//This is your host and then your username and then finally your password
$db = mysql_connect("localhost","username","password");
//The function mysql_select_db() sets the current
//database to the one specified in this case "test"
mysql_select_db("test" ,$db);
//mysql_query() execute the specified MySQL query in this case
//we are are storing this in the variable $sql
$sql = mysql_query("SELECT * FROM links" ,$db);
//now we wil start producing a table
echo ("<table border ='1'>");
//this part displays our headings
echo ("<tr><td>url</td><td>description</td></tr>");
//the mysql_fetch_row() function fetches the next row in the resultset
//and stores this in an array , in this case $tablerows
while ($tablerows = mysql_fetch_row($sql))
{
//we now finish our table off by inserting values into each
//column . $tablerows[1] is equivalent to our url field and
//$tablerows[2] is the description field
echo("<tr><td><a href='$tablerows[1]'>$tablerows[1]</a></td><td>$tablerows[2]</td></tr> ");
}
echo "</table>";
//close database (good practice)
mysql_close($db);
?>
|