Hi Very intersting ,posting here to subscribe the thread and be informed the progress.
Wishing you good luck
OK, did you ever think about creating your own blog?
I know it sounds complicated but it's not. You need a database, and a couple of PHP files to start.
The idea of this thread is to create a simple blog step by step.
First we'll create a database, a simple backend and a simple CSS style.
Later we'll expand all of this, add new functions, effects, enhace the look of the blog and so on.
This thread will be updated at least once a week with new functions for the blog until we end up with a completely finished blog application.
Once finalized this blog could power your personal blog.
I know there are many free blog solutions available on the net and they all have more features than this blog will ever have (unless I get a very large open source development community), but creating your own blog would give your site a unique look and feel. And this script, once written can be easily modified to act as a CMS.
OK, this was the intro. First lesson tomorrow.
Hi Very intersting ,posting here to subscribe the thread and be informed the progress.
Wishing you good luck
And I post for exactly the same reason![]()
Looking forward to the first lesson ! Great idea.
Take a look at Eric's Books Site to know what I read or at Eric's Fotosite to see my pictures.
melkior that is a great ideamaybe we can all contribute to this project
Well, when the blog is finished anyone can expand it as he sees fit.
The base idea of this thread is for it to be a tutorial for now.
But thanks for your offer.
OkI guess I didn't read very good the first post
anyway I'll keep an eye on this thread
Well seeing that this thread caused interest I better move along.
Well, first of all, let me tell you that this tutorial will be written for those who have an elementary knowledge of PHP, HTML and MySQL although it's not necessary.
I'll try to keep it as simple as possible and you can ask me about the details on any part of this project anyway.
OK, a little bit of theory for a start.
The logic behind the basic functions of a blog is fairly simple:
Each blog consists of 3 parts (2 if you divide them by type). First part is the user interface. In this case it'll be a collection of PHP scripts which will work as a whole to generate the pages for the visitors to view.
Second part of the blog is the administration control panel which allows the admin (in this case you) to add new posts, add links to the blogroll and so on.
And the final, third part is the database. The database contains all the posts, links and everything else in your blog.
These 3 parts interact together and create what we call a blog.
The user interface fetches the data from the database and formats it as a webpage, while the admin control panel inserts the data into the database.
OK, next post -- some real programming.![]()
Before writing any code we need to design the database cause we really need to know what data we'll be using in the script and also what functions we'll need to create.
We'll start with a simple database - it will use only one table. We don't need too much at first anyway.
We'll need a date on the posts, their titles, the text in the post and we'll add an ID for the posts (we'll need that later).
So here's the SQL code for creating the table. You can run this query in phpmyadmin after creating the database or import it or whatever suits you.
So now we have a table named blog ready for our inputs.Code:CREATE TABLE `blog` ( `id` INT( 128 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `date` TIMESTAMP NOT NULL , `title` VARCHAR( 100 ) NOT NULL , `text` TEXT NOT NULL );
We'll be expanding this database in future tutorials.
Now that we have a database ready we need something to input the data and something to display the data from the database.
First, what we'll do is create a config.php file. It will include settings for the database connection and some other configuration info.
Here's the code:
We'll include this file in our other files in the next step.PHP Code:<?php
$dbuser = 'username'; //database username
$dbname = 'blog'; // database name
$dbpass = 'password'; //database password
$dbhost = 'localhost'; //database host -- usually 'localhost' but best to check with your host
$sitename = 'My Blog'; //name of your site
mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
?>
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:
We start by including the data from the config file which also manages connecting to the database for us.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();
?>
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks