Going through website creation part 2: Backend

This step mainly involves breaking the site up into sections of PHP. This will allow us to use various parts and pieces to make the site dynamic.

We may want to create a database and for this article I will be creating a very simple design that is just going to be used to display the information on the page. We will do this by adding a simple connect.php page that will contain the connection information.

1
2
3
4
5
6
7
8
<?php
 
$con = mysql_connect('database.website.com','username','password');
if (!$con) {
die('Could not connect: ' . mysql_error());
} mysql_select_db('databaseName');
 
?>

Now that we have successfully created our connect.php file we can move on to create a small piece of code we will include in the body of the page we created in the first tutorial. In this file we will be selecting information from our database.

1
2
3
4
5
6
7
8
9
10
11
<?php
 
include('connect.php');
$loader = mysql_query("SELECT * FROM table ORDER BY title") or die(mysql_error());
while($row = mysql_fetch_array($loader)) {
 
echo .$row[title].'<br>'.$row['description'].'<br>'.$row['link'].'<br>'.$row['quality'];
 
}
 
?>

Now we have successfully pulled information from our database, created a connection to the database and loaded the connection dynamically. Hopefully this will have helped you in your journey to create a dynamic website.

Related posts:

  1. Going Through Website Creation Part 1: Layout
  2. Getting Secured Using Mysqli
  3. The Beginners Guide to PHP
  4. Create Your Own PHP/AMF Data Service For Flex
  5. Stop Direct Page Access With PHP
Caleb Jonasson

About: Caleb Jonasson

I am a web application developer currently spending my days coding at work, completing contracts and running around with my Nikon. This is my primary place for updates and everything code, technology and database related.
  • http://codewithdesign.com/2009/11/13/going-through-website-creation-part-1-layout/ Going Through Website Creation Part 1: Layout | Code With Design

    [...] Continue on to read part 2 [...]