Free Webmaster Resources .info
PHP Introduction and Tutorials Javascript  Introduction and Tutorials HTML  Introduction and Tutorials ASP  Introduction and Tutorials Free Internet Access Guide and Directory Webspace  Directory Webhosting  Directory Adult Webhosting  Directory PHP Hosting  Directory ASP Hosting  Directory
à Navigation
» Home
» Php Introduction
» Php Tutorials
» Submit Scripts
 
Subscribe for free!

Join our mailing list today and recieve free updates monthly with web hosting specials!
 
 

 

 

Free Webmaster Resources .info | Free PHP Tutorials


Creating a database

This will connect to the database samplelinks and then display all the information in the links table in an HTML table on your page . You will have to replace the localhost , yourname and password with your own information .

<?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","yourname","password");
//The function mysql_select_db() sets the current
//databse to the one specified in this case "samplelinks"
mysql_select_db("samplelinks" ,$db);
//mysql_query() execute the specified MySQL query in this case
//we are are storing this in the variable $sqlquery
$sqlquery = 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($sqlquery))
{
//we now finish our table off by inserting values into each
//column . $tablerows[0] is equivalent to our url field and
//$tablerows[1] is the description field
echo("<tr><td>$tablerows[0]</td><td>$tablerows[1]</td></tr> ");
}
//close the database
echo "</table>";
?>

Now some people may be dissapointed to see that the links do not work , well we make the following alteration to the code above and this will rectify this.

echo("<tr><td><a href='$tablerows[0]'>$tablerows[0]</a></td><td>$tablerows[1]</td></tr> ");

In the next tutorials we will add and delete records using this database

[more][1] [2]

Recommended Webhosting Company
Webhosting
Find: Webhosting. Review & Compare!

 

 
Related Websites
 


Free Email
Your source to free email.

Free Casino Downloads
Contains useful free casino downloads.

Free Software Downloads
A complete collection of free software downloads.

Free
Download free stuff from psike.com your free stuff resource.

Free Teen Online Dating
Meet other singles for free online dating.

Coolfreeweb.com
The Free category at coolfreeweb.com

My Directory Listing
A massive directory listing of websites

Website Collation Project
The website collation project contains a huge directory of websites.


 
Top Webhosts
 
 1. Webhosting
 2. free web hosting Web Ho
 3. Free Web Hosting Info
 4. Free Web Hosting Info
 5. Free Web Hosting
 
-
- Give us feedback
 
Last updated
Nov 19, 2008
Free Webmaster Resources .info | A resource must for every web master
Untitled Document - Web Hosting
- PHP Hosting
- Free Internet Access