Well, we have the config file.
We need something that will display our blog.
We need to create an index.php file.
This is the source code:
PHP Code:
<?php
include ("config.php");
?>
<HTML>
<HEAD>
<TITLE><?php echo $sitename; ?></TITLE>
</HEAD>
<BODY>
<H1><?php echo $sitename; ?></H1>
<?php
$sql ="SELECT * FROM blog ORDER BY id DESC LIMIT 10";
$result=mysql_query($sql);
while ($record = mysql_fetch_object($result)) {
echo "<dt><b>$record->title</b></dt>";
echo "<em>$record->date</em>";
echo "<dd>$record->text</dd>";
echo "<p></p>";
}
?>
</BODY>
</HTML>
<?php
mysql_close();
?>
We start by including the data from the config file which also manages connecting to the database for us.
After that we switch to HTML to format a normal web page but we include dynamic content.
We use the PHP echo statement to write out the name of the site in the header and also in the first line after the opening BODY tag. The name is taken from the $sitename variable in the config.php file.
We again switch to PHP in the body section to select all the data from the database, we use a while loop to continue fetching data until we reach the end of the database. We order it by the id stored in the database and it's descending (to show the latest posts first). We're also limiting the selection to 10 entries.
The retrieved data is stored in the $record and we can access the parts we need by writing $record->name_of_what_we_need
So we write out the data, first the title, than the date and finally the post itself. We format it with a little bit of HTML and that's it.
Later today I'll post the source code of the script we'll use to insert data, and set up a live example.