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.