PHP Blog

How to Create an Object-Oriented Blog Using PHP

Oct 20th in PHP by Ben Mills

In the past few weeks NETTUTS has posted quite a few great tutorials on how to get started using PHP and MySQL to create simple web applications such as a shout box. Today we are going to take our knowledge of PHP and MySQL a step further by creating a simple blog. While there are countless excellent free blog platforms, the purpose of this tutorial is not to make a "better" blog but to use the process of making a blog to learn about advanced database structure techniques and how to use data more efficiently by utilizing objects in PHP.

PG

Author: Ben Mills

Ben Mills is a web developer who lives in Chicago. He can often be found riding around the city on his baby blue scooter.

For this tutorial it is assumed that you have some basic understanding of PHP, MySQL, XHTML, and later on jQuery / JavaScript.

Part 1) Creating our Database

Before we move into our MySQL client and start creating our tables, we should to lay out what we want in our blog. The obvious thing we need to hold is blog posts, and in each post it should contain a title, the post, an author, and the date it was posted.

Now we could just make one table to hold that information, and most likely accomplish creating a basic blog, but with just one table we will not have as much control over our data. For example, we could just store the name of the author in the same table as the blog post, but what if we want to also store the author's email? Sure! We just add another field to our table would be the obvious solution.

The problem comes up when down the road you want to change the email address of that author. Now you have to change it for every single blog post that person has created.

So what we are going to do is make a separate table called "People" and in this, we will store all the information we need from the author - such as emails, URLs, their name, and a unique ID. Then in our blog post table we will point to the person we want using that person's unique ID. This id is referred to as a foreign key and the relationship between the blog post table and the people table is called a one-to-many relationship.

One other thing we want to have in our blog is a tag for each blog post. Again we want to make our database efficient so we will create a separate table for our tags. Now what do we do? Should we create a field in the blog post table that is a foreign key for our tag? The problem with using a one-to-one relationship this time is sometimes blog posts have more than one tag; so again, we will use a one-to-many relationship. To do this we need to create another table that will be called something like "blog_post_tags" that will hold two foreign keys, one will be the blog post's ID and the other will be the tag ID that the blog post is associated with. This way we can assign as many tags as we want to a blog post but can still edit the information about that specific tag across all posts with a simple MySQL query.

Now that we have outlined what we want our database to look like, let's create it. I'll be using PhpMyAdmin since that is the most widely used MySQL admin client. There are a few different naming conventions you can use when creating your database, table, and field names. I personally like to use all lowercase and underscores in place of spaces.

Note: If you do not have PHP and MySQL on your system or a server that can run it, I recommend downloading a stand-alone install of Apache, PHP, and MySQL. MAMP is good for Macs and WAMP is good for PCs.

First we need to create our database, I'm going to call it "nettuts_blog".

Next, we will create our tables; the first will be "blog_posts".

"blog_posts" will have five fields: "id", "title", "post", "author_id", and "date_posted". For "id" we are going to make it the primary key and set it to auto-increment. What this will do is generate our unique id for us. Each time we add a post it will give it a number starting at one and moving up for as many posts as we have.

Now we also need to set the variable type for each field. The id will be set to type int, short for integer, since it can only be a number and we will set the max length to 11. The field "title" will be set to type varchar with a max length of 255. The "post" field will be type "text" and we will not set a max length since posts can be very long. "author_id" will be the same as "id" but we will not set it as our primary key or have it auto increment, and we will set "date_posted" to type "Date".

Our next table will be "people". We are not calling it "authors" because down the road we might want to create the ability to register and post comments and those people would not be considered authors.

"people" will contain five fields also: "id", "first_name", "last_name", "url", and "email".

"id" will be set as an int, the primary key, and to auto increment, the same way we set id of "blog_posts". "first_name", "last_name", "url", and "email" will all be set to type varchar with a max length of 255.

Our next table will be "tags" and will for now contain only two fields: "id" and "name". Down the road we could make this more complex by adding a description but for this tutorial, we will not. As we did before "id" will be set as int, the primary key, and to auto increment. "name" will be type varchar and have a max length of 255.

And our last table, "blog_post_tags", will have only two fields: "blog_post_id" and "tag_id". They will both be set to type int with a max length of 11. As you most likely noticed, we did not set a primary key for this table. This is because we will never be getting data out of this table unless we are asking for a specific blog post or all posts of a specific tag id.

Part 2) Creating our Objects in PHP

Before we start into our actual PHP code we need to create our files and folders, for this tutorial we will have our index.php in our root folder then an includes folder that will hold our CSS style sheet, our JavaScript files, includes.php that will hold references to our objects and MySQL connection, and blogpost.php that will hold our BlogPost obejct.

Now that we have our database set, we need to create the objects in PHP that will handle the data for us. Objects in programming are a way to pull together different attributes (as variables) and methods that all relate to the same thing. Objects also help us organize our programs much more. Before we jump into our objects for our blog, let's just create a simple object so that we can illustrate what they are in a more "real life" term.

Our object will be called "Bike", now there are two types of things each object has, properties and methods. Properties define the object and methods are what the object does. For example our Bike object would have properties like wheel size, number of gears, and perhaps the frame size. For methods we might have something like "Pedal".

Now to move back to our blog, we only need one object for now called "BlogPost". BlogPost will have six properties, id, title, post, author, tags, and date posted. So lets make it in PHP.

To define an object in PHP we define it as a "class". A class is the structure of each object, or as wikipedia describes it, "In object-oriented programming, a class is a programming language construct that is used as a blueprint to create objects. This blueprint includes attributes and methods that the created objects all share." (http://en.wikipedia.org/wiki/Concrete_class). We are going to open up our blogpost.php page and define our first object.

Note: In each section of the tutorial, I'm going to leave out the opening and closing PHP tags; "<?php" and "?>" you will need to include them at the start and end of your document.

class BlogPost
{
}

In our class we need first define our properties. To do this, we have to create variables - but with "public" in front of them. Just a quick note, if you are using PHP4 then you will need to use "var" instead of "public".

class BlogPost
{
	public $id;
	public $title;
	public $post;
	public $author;
	public $tags;
	public $datePosted;
}

Now that we have all our properties defined, we want to define our first method. Methods are also described as functions, but the main difference is that a method is a function inside an object. So all methods are also functions but not all functions are methods.

Our first method will be what is called a constructor; this method is automatically called whenever we make a new instance of the BlogPost object.

The common use of a constructor is so that you can create a new object and set the properties of that object quickly.

So what we want to do is create a new function called __construct() and we are going to pass in five values, id, title, post, author id, and date posted. For each variable name we are going to put "in" before the word so we can tell inside our functions what variables are being passed in and what variables are already present.

class BlogPost
{
	public $id;
	public $title;
	public $post;
	public $author;
	public $tags;
	public $datePosted;

	function __construct($inId, $inTitle, $inPost, $inAuthorId, $inDatePosted)
	{

	}
 }

The problem here is that, with this current code, every time we create a new instance of BlogPost we need to supply all those properties. But what if we want to make a new blog post and have not defined those variables yet? To handle this, we need to "overload" the arguments for our function so that if we call the function and don't pass in one of the arguments, it will automatically set it to the default value.

function __construct($inId=null, $inTitle=null, $inPost=null, $inPostFull=null, $inAuthorId=null, $inDatePosted=null)
{
}

As you can see, all that we do to accomplish our task is set each argument to the value "null". Now inside our constructor, we need to set each of our variables to our passed in values. To do this we want to set them to the object we are in right now; We can do this with the "this" keyword. Unlike many other languages to access a property in PHP you use "->" where in most languages (I.E. JavaScript, ASP.NET) you use ".".

function __construct($inId=null, $inTitle=null, $inPost=null, $inPostFull=null, $inAuthorId=null, $inDatePosted=null)
{
	$this->id = $inId;
	$this->title = $inTitle;
	$this->post = $inPost;
}

This works for id, title, and post. But what about our other ones? For date we are going to need to reformat the data we got from MySQL to be more readable. That's easily accomplished; We just explode it (also known as splitting in other programming languages) and then put it back together. MySQL gives it to us in this format yyyy-mm-dd, so if we explode it using "-" as our separator we will get an array holding three values. The first will hold our year, the next will hold our month, and the last will be the day. Now all we do is put them back together in whatever format we want. I am going with mm/dd/yyyy.

$splitDate = explode("-", $inDatePosted);
$this->datePosted = $splitDate[1] . "/" . $splitDate[2] . "/" . $splitDate[0];

For the author, all we have to do is ask the database for the person with the id of our author ID. We can do this with a basic MySQL query.

$query = mysql_query("SELECT first_name, last_name FROM People WHERE id = " . $inAuthorId);
$row = mysql_fetch_assoc($query);
$this->author = $row["first_name"] . " " . $row["last_name"];

Left Join

Now the tags will be slightly more difficult. We are going to need to talk to the database, so we need to create a MySQL query. We won't worry about the database connection right now, that will be defined outside of this class. Now all we have is the blog post's ID. We can compare that to the blog posts tags in our blog_post_tags table but then we will only get back the tag's ID and will need to do another query to get the information about the tag. That's no good; We want to be efficient so let's do it in just one query!

To do this we are going to do what is called a left join, this means we are going to also select data from another table but only when it matches the data from the "left" or our other selected data. So first let's just get all tag IDs that are associated with our blog post's ID in the blog_post_tags table.

$query = mysql_query("SELECT * FROM blog_post_tags WHERE blog_post_tags.blog_post_id = " . $inId);

Now let's add our left join and tell our query we only want the data in the tags table:

$query = mysql_query("SELECT tags.* FROM blog_post_tags LEFT JOIN (tags) ON (blog_post_tags.tag_id = tags.id) WHERE blog_post_tags.blog_post_id = " . $inId);

So now the query is selecting all from the tags and blog_posts_tags tables where, first blog_post_tags.blog_post_id equals the one we provided and then also returns the information about each tag that has that tag_id that is in the same row of data as our blog_post_id.

Now we want to process that data in PHP with a simple while loop. We are going to also create two arrays that will hold our data: one for the tag name, and the other for the tag id. We will also make a string to hold all of our tags. We first will set it to "No Tags" so that if we return no data from our MySQL query, it will return that we have no tags, otherwise that value will be overwritten with the tag names.

$postTags = "No Tags";
$tagArray = array();
$tagIDArray = array();
while($row = mysql_fetch_assoc($query)
{
	array_push($tagArray, $row["name"]);
	array_push($tagIDArray, $row["id"]);
}

Now we will check to make sure if the array has a length greater then zero (we don't want to perform all of this extra code if we don't have to). Next, for each tag in our tag name array, we are going to concatenate a string of tags. We will use a simple if else statement.

if (sizeof($tagArray) > 0)
{
	foreach ($tagArray as $tag)
	{
		if ($postTags == "No Tags")
		{
			$postTags = $tag;
		}
		else
		{
			$postTags = $postTags . ", " . $tag;
		}
	}
}
$this->tags = $postTags;

You most likely noticed that we did not use the tag id arrays. We are going to leave those alone for now and come back to them later. We just want to get our blog up and running first.

The last step for our class is to add if statements for each property so that if we pass in nothing, it will not try to set the current object's property to nothing (this will cause an error). Here is the entire BlogPost class with the if statements added:

<?php

class BlogPost
{

public $id;
public $title;
public $post;
public $author;
public $tags;
public $datePosted;

function __construct($inId=null, $inTitle=null, $inPost=null, $inPostFull=null, $inAuthorId=null, $inDatePosted=null)
{
	if (!empty($inId))
	{
		$this->id = $inId;
	}
	if (!empty($inTitle))
	{
		$this->title = $inTitle;
	}
	if (!empty($inPost))
	{
		$this->post = $inPost;
	}

	if (!empty($inDatePosted))
	{
		$splitDate = explode("-", $inDatePosted);
		$this->datePosted = $splitDate[1] . "/" . $splitDate[2] . "/" . $splitDate[0];
	}

	if (!empty($inAuthorId))
	{
		$query = mysql_query("SELECT first_name, last_name FROM people WHERE id = " . $inAuthorId);
		$row = mysql_fetch_assoc($query);
		$this->author = $row["first_name"] . " " . $row["last_name"];
	}

	$postTags = "No Tags";
	if (!empty($inId))
	{
		$query = mysql_query("SELECT tags.* FROM blog_post_tags LEFT JOIN (tags) ON (blog_post_tags.tag_id = tags.id) WHERE blog_post_tags.blog_post_id = " . $inId);
		$tagArray = array();
		$tagIDArray = array();
		while($row = mysql_fetch_assoc($query))
		{
			array_push($tagArray, $row["name"]);
			array_push($tagIDArray, $row["id"]);
		}
		if (sizeof($tagArray) > 0)
		{
			foreach ($tagArray as $tag)
			{
				if ($postTags == "No Tags")
				{
					$postTags = $tag;
				}
				else
				{
					$postTags = $postTags . ", " . $tag;
				}
			}
		}
	}
	$this->tags = $postTags;
}

}

?>

Now that our object class is complete, most of the hard stuff is done! Now all we have to do is set up our database connection and the HTML to display our posts!

Part 3) Fetching the Data From MySQL and Displaying it With PHP

Before we do anything we need to set up our includes.php file to hold a reference to our BlogPost object and connect to our MySQL database. First lets include our object with a simple include statement:

include 'blogpost.php';

Now lets add our database connection:

$connection = mysql_connect("localhost", "username", "password") or die ("<p class='error'>Sorry, we were unable to connect to the database server.</p>");
$database = "nettuts_blog";
mysql_select_db($database, $connection) or die ("<p class='error'>Sorry, we were unable to connect to the database.</p>");

Next, we need to retrieve our blog posts from the database. To do this, we're going to make a function that can take up to two arguments. We will overload both of them; so you can call the function with either 0, 1, or 2 arguments.

function GetBlogPosts($inId=null, $inTagId=null)
{

}

Inside our function we need to check to see what arguments were passed in and create our MySQL query accordingly.

function GetBlogPosts($inId=null, $inTagId =null)
{
	if (!empty($inId))
	{

	}
	else if (!empty($inTagId))
	{

	}
	else
	{

	}
}

So what we are doing here is asking if each argument is not empty, the reason we are using the empty function instead of just doing the standard "!= null" comparison is because empty not only checks if the variable is null, but if it empty as well (I.E. ""). Now we will write a query depending on what variables we have. If we pass in a blog post ID we just want that single blog post, if we give the function a inTagId we want all posts that have that tag, and otherwise we just want all blog posts in our database.

if (!empty($inId))
{
	$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC"); 
}
else if (!empty($inTagId))
{
	$query = mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" . $tagID . " ORDER BY blog_posts.id DESC");
}
else
{
	$query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
}

The next step is to process the data returned from each query, create the objects, and then add them to an array to return.

$postArray = array();
while ($row = mysql_fetch_assoc($query))
{
	$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['postfull'], $row['firstname'] . " " . $row['lastname'], $row['dateposted']);
	array_push($postArray, $myPost);
}
return $postArray;

Here is the entire includes.php file's code:

<?php
include 'blogpost.php';

$connection = mysql_connect('localhost', 'username', 'password') or die ("<p class='error'>Sorry, we were unable to connect to the database server.</p>");
$database = "nettuts_blog";
mysql_select_db($database, $connection) or die ("<p class='error'>Sorry, we were unable to connect to the database.</p>");

function GetBlogPosts($inId=null, $inTagId =null)
{
	if (!empty($inId))
	{
		$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC"); 
	}
	else if (!empty($inTagId))
	{
		$query = mysql_query("SELECT blog_posts.* FROM blog_post_tags LEFT JOIN (blog_posts) ON (blog_post_tags.postID = blog_posts.id) WHERE blog_post_tags.tagID =" . $tagID . " ORDER BY blog_posts.id DESC");
	}
	else
	{
		$query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
	}

	$postArray = array();
	while ($row = mysql_fetch_assoc($query))
	{
		$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['postfull'], $row["author_id"], $row['dateposted']);
		array_push($postArray, $myPost);
	}
	return $postArray;
}
?>

Now we can move on to displaying our data, lets open up our index.php file and set up a basic HTML page. Inside our body we'll create a division with an id of "main" that will contain our blog. We will give our blog a title and then have a second div inside main that will be called "blogPosts".

<div id="main">
	<h1>My Simple Blog</h1>
	<div id="blogPosts">

	</div>
</div>

Inside our blogPosts div, we'll put in some PHP so that we can display our posts. First we are going to include our includes.php file and then call our GetBlogPosts function with no arguments to get all our blog posts and set that to an array called blogPosts.

<?php
include 'includes/includes.php';

$blogPosts = GetBlogPosts();
?>

Now, we will use a foreach loop to display our blog posts. What a foreach loop does for us right now is takes an array and executes the code in the loop for each item in the array, you could also use a normal for loop to achieve this but a foreach loop requires less code.

foreach ($blogPosts as $post)
{

}

Inside the loop, we use $post as the current array item, and since $blogPosts is an array of BlogPost objects we can simply use "->" to access each property that we want. Lets start by just echoing out the title of each blog post to our page and just add a <br/> - as an example.

foreach ($blogPosts as $post)
{
	echo $post->title . "<br/>";
}

If we go to our database and insert some fake data, then open up index.php in a browser, we will get something like this:

Let's really build our posts in HTML. Each post will be wrapped in a div with a class of "post". Then we will have the post title inside an h1 tag and the actual post inside a <p> tag.</p>

foreach ($blogPosts as $post)
{
	echo "<div class='post'>";
	echo "<h2>" . $post->title . "</h2>";
	echo "<p>" . $post->post . "</p>";
	echo "</div>";
}

Let's also give each post a footer that will include the post's author, date posted, and the post's tags. We will put all of this information within a span tag with a class "footer".

foreach ($blogPosts as $post)
{
	echo "<div class='post'>";
	echo "<h1>" . $post->title . "</h1>";
	echo "<p>" . $post->post . "</h1>";
	  echo "<span class='footer'>Posted By: " . $post->author . " Posted On: " . $post->datePosted . " Tags: " . $post->tags . "</span>";
	echo "</div>";
}

Now let's look at our index.php file again in a browser:

Looks like its all working! Next, let's add some styling.

Much better; you can view this online here or click the big "demo" buttons. Thats it for this tutorial. In a subsequent tutorial, we will add more functionality to our blog, including some nice AJAX functionality!

I hope you now have a better understanding of how object oriented programming works. Even if you end up doing the majority of your development using a framework, its very important to have a core understanding of the fundamentals. If you have any specific questions about this tutorial, don't hesitate to tweet me @benemills. I would like to give a special thanks to James Padolsey for helping me with this article.

Stay tuned for Part 2!

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.


Related Posts

Check out some more great tutorials and articles that you might like

Enjoy this Post?

Your vote will help us grow this site and provide even more awesomeness

Plus Members

Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.

Join Now

User Comments

( ADD YOURS )
  1. PG

    insic October 20th

    Another great tutorial series I had to follow in nettuts…

    ( Reply )
    1. PG

      Adrian Chan November 10th

      Hi cutie want to let me explode($in_you) ? :D =D

      ( Reply )
  2. PG

    Ryan October 20th

    Thanks for posting. I don’t have time to read this all now, but will later today. This is just the type of info I’ve been looking for.

    ( Reply )
  3. PG

    Drew Barontini October 20th

    This is great, Ben. Please keep them coming. I’m just now delving into PHP OOP and I’m enjoying it, but it does take some getting used to and thinking in an ‘object-oriented’ way.

    ( Reply )
  4. PG

    THE MOLITOR October 20th

    Awesome! Now I can implement simple blogs into my clients websites without having to use Wordpress!

    ( Reply )
  5. PG

    Robert October 20th

    Hi!
    Nice tutorial, but it seems, that there are some formatting errors in the __construct() function of the BlogPost Class.
    The empty() function isn’t displayed correctly, example in line 15:
    if (!emptyempty($inId))

    Robert

    ( Reply )
  6. PG

    Dan Harper October 20th

    Looks very detailed, nice one! I’ll read through it later.

    ( Reply )
  7. PG

    Tommy M. October 20th

    This is a great tutorial mostly for explaining clearly how to harness Object Oriented Programming. Awesome stuff. Keep up the good work!

    ( Reply )
  8. PG

    Barttos October 20th

    Nice tutorial! But exists things that could be done better

    echo “$post->title”; is faster

    “SELECT * FROM blog_posts ORDER BY id DESC” – about selecting all field i wrote here http://barttos.net/2008/10/09/optimizing-mysql-queries/

    ps. http://barttos.net/bts_upload/oop_blog_20_10_08_65832.jpg (Opera 9.60)

    ( Reply )
  9. PG

    Tim October 20th

    Great Tutorial! PHP has never seemed more approachable, especially from the perspective of an ASP.NET guy. I didn’t even know you could do OOP in PHP so obviously I need to check it out again. Keep up the great work!

    Side-note: For some reason, the demo is not closing tags properly so I think this might be the cause of the Opera problem. I’m seeing a lot of </p and </span

    ( Reply )
  10. PG

    Julien October 20th

    An excellent way to learn object-oriented in PHP, good work !

    ( Reply )
    1. PG

      Geet prasad July 13th

      yap,its really very good oppurtunity to have a great idea about blog in php………..

      ( Reply )
  11. PG

    John October 20th

    Yeah, nice! These were some good tips for a future project. I’m kind of a greenhorn in PHP/MySQL, so more tuts in these areas are appreciated! A nice, secure-minded login/register tutorial in PHP/MySQL is the one I want the most.

    ( Reply )
  12. PG

    Ignace Knops October 20th

    And I thought that in oo programming it was all about encapsulation and your entire application was covered in oo and you used an invoker to kick-off your application? What was I thinking…

    ( Reply )
  13. PG

    James October 20th

    Nicely done Ben! :) … One thing, the post time/date does not seem to be showing on the demo.

    Looking forward to part 2!!

    ( Reply )
  14. PG

    Bogdan October 20th

    I haven’t read the article yet, I’ve only scanned through the code and I can’t help but wonder why you didn’t use the mysqli extension instead of the old, procedural, mysql functions (since this is an oop tutorial and all, and from the class constructors I’m guessing it’s for php5 and higher).

    ( Reply )
  15. PG

    Buzu October 20th

    Just one thing. In this part:

    The problem with using a one-to-one relationship this time is sometimes blog posts have more than one tag; so again, we will use a one-to-many relationship.

    You are actually using a many-to-many relationship. That’s why you are creating the lookup table.

    Great tutorial.

    ( Reply )
  16. PG

    Bogdan October 20th

    Oh and, what’s up with visibility of your functions? I mean you used some visibility keywords on variable declarations but not on function declarations.

    ( Reply )
  17. PG

    Ben Mills October 20th

    Thanks for the comments everyone!

    @Barttos your right things could be done a little faster, thanks for point that out! Also I looked at your screen shot and checked my index.php file and realized that I forgot the “>” on the closing p tag and span tag. I updated the demo to fix this.

    @James yeah the date display also had a small typo, in the first version of this I wrote I was using inconstant col. names and I decided to go with the firstword_secondword style, but I didn’t change that in my GetBlogPosts function, it was looking for “dateposted” when the real col. name is “date_posted”.

    ( Reply )
  18. PG

    Eduardo October 20th

    exactly what i need! very nice tutorial! keep posting stuff like this! =)

    ( Reply )
  19. PG

    Pat Arlt October 20th

    These basic mysql and php tutorials are some of the best on nettuts this will keep me busy for a long time.

    Thanks alot

    ( Reply )
  20. PG

    Jacob Gube October 20th

    It’s worth noting that the __construct() method will only work in PHP 5 (which recently just became the stable version this year), so if you’re still sporting PHP 4, you have to use:

    class BlogPost
    {
    function BlogPost() {

    }
    }

    ( Reply )
  21. PG

    Miles Johnson October 20th

    The PHP is good but theres no point in using an object here, your just using more unnecessary memory.

    It would be a lot easier and a lot faster to simple to an associative array and a few basic queries within 1 function.

    function getBlogPosts($limit,$offset) {
    //…
    }

    ( Reply )
  22. PG

    Miles Johnson October 20th

    It would be a lot easier and a lot faster to simpley return an associative array and use a few basic queries within 1 function.*

    Man I should reread before submitting.

    ( Reply )
  23. PG

    Thijs October 20th

    Good Article!!

    ( Reply )
  24. PG

    Diego Gomes October 20th

    Real great!

    What about rails form scratch series? is it over?

    ( Reply )
  25. PG

    Ben Mills October 20th

    @Jacob Gube Yeah that is true, and that’s a good thing to point out as I’m sure some people are stilling using PHP 4, another PHP 4 / 5 difference that I did note in the article is that you need to use “var” before each of your class properties in PHP 4, but in 5 you use “public” instead of “var”.

    ( Reply )
  26. PG

    Ben Mills October 20th

    @Miles Johnson In a real life situation I very much agree, the main point of this was not to make an efficient PHP blog, it was to introduce PHP OOP to people who are new to it.

    ( Reply )
  27. PG

    Miles Johnson October 20th

    @Ben – Yes but then most likely all the “beginners” will think that they should apply this to every aspect of PHP dev and that OOP should be used for everything. The only time to really use OOP is when you are storing data in the object (say a user array) and then manipulating it.

    ( Reply )
  28. PG

    Niklas October 20th

    Indeed an interesting post today! Very nice!

    ( Reply )
  29. PG

    Marcus Dalgren October 20th

    As far as I can see there’s absolutely no reason to make all of the class variables public. If you’re going to teach OOP then you should teach people to only expose the parts of the class that need to be exposed. Right now anyone can just type for example $blogPost->$id = “whatever” which is probably not what you want. Only your class should be able to touch the attributes directly and you should use get/set methods if you want people to be able to access them manually.
    Also you should declare your methods as public as well for claritys sake.

    ( Reply )
  30. PG

    Shane October 20th

    Lots of interesting ideas and concepts. I’m one of many people who’s chosen Wordpress rather than write something from scratch, but it’s good to see some hand-built stuff :)

    ( Reply )
  31. PG

    Banago October 20th

    These kind of tutorials are good for learning PHP and MySQL too. Thanks very much!

    ( Reply )
  32. PG

    Christian Dalsvaag October 20th

    @Barttos: I just read your blogpost about “optimizing MySQL Queries”… I quote: “Even if you really needed all the fields in the table, the better their list. It increases the readability of code. If you use an asterisk is impossible to know which fields are in the table, without opening it.” – I really must say that, that is the most bullshit reason I have ever heard. “Do not know which fields are in?” Whaat? Really, do not recommend people to use that blog-post, if you want to point people in the right direction, at least give good reasoning! Why should you not select all? Well, to decrease traffic generated by queries in LARGE tables. This is so insignificant if you are running a mediocre blog, with 20 posts in it, and a few rows.

    Anyway, I really didn’t like this blog. I don’t like the structure of the classes, and I didn’t like that you separated “GetBlogPosts” from the class. I also would recommend you to use better naming, i.e “findById();”, “findAll()” etc. I have an example of my classes posted in a pastebin below;

    http://pastie.org/296539

    THAT class is a good example to follow!

    ( Reply )
  33. PG

    Christian Dalsvaag October 20th

    Ok, it seems like I wasn’t done commenting this thing.. here we go – and by the way, you’re in for a ride!

    1. You start by setting all variables to Public, why would you do that? Variables are PUBLIC BY DEFAULT, so if you aren’t below a PRIVATE statement it is totally useless code.
    2. __constructor is to be DEPRECATED, use the name of the class – i.e “class Article” would make a __constructor; “function Article()”
    3. Why on EARTH would you allow the user to call $bp = new BlogPost; without any variables? What good does this class do without any variables? Setting all that shit to NULL is UNNECESSARY! You would anyway have to call …BlogPost(’Title’, NULL, ‘Description’, NULL, ‘Date’), etc. if you knew the description but not the author etc. go get what I mean.
    4. The fact that you even used LEFT Join impressed me. Good work! Nice example to follow!
    5. WHAT THE COW are you DOING with all those IF blocks?! if empty, bla bla bla – DID you know;
    1. You do NOT, I repeat NOT; have to use curly-brackets for single line if-s.
    2. You could solve the same thing using the ternary operator.
    6. Your classes are a huge dump of shit. I’m not even going to reason this. Check the class I made in the pastie in my previous comment.

    You really need to know more about class structure, and WHY you do the things you do – before recommending people to do it.

    And I don’t blame you alone, wtf is going on with the moderators on this page? They talk about quality? This is not quality! I would never pay anything for this. Guys, get REAL E-D-U-C-A-T-E-D people to DO the articles. Unless someone writes a good article like the CakePHP one, I’m dropping this site. And so is my company for resources.

    ( Reply )
  34. PG

    Michael October 20th

    Great tutorial, I wanted to go through the source more closely but I can, I get the following error when trying to download…

    “AccessDeniedAccess Denied298DC82F0AA9D6B3BWSoTIwXzxh5MsTpIUzUkMsVPUSXMKhHg/AA0exJMNMHvDqVi+TU6UNJaX63+mMT”

    Anyone else getting this?

    ( Reply )
  35. PG

    Bogdan October 20th

    I might be getting a little off topic here but anyway, Christian, since when the hell’s __construct been deprecated?

    ( Reply )
  36. PG

    Nate Klaiber October 20th

    Why the extra functions outside of the class? Why not create them as static methods within the BlogPost class? Then, instead of random functions outside of the scope of the class (and SQL, which should be encapsulated in that model), you could call $posts = BlogPost::find_all(); The static find method could be all, could be an id, could pass in options if you wanted, then it can get the posts and create new instances of BlogPost for each row found.

    I know this is meant to be a simple example, so I understand the premise – just seeing areas where things could be more organized and encapsulated, to really harness the OOP benefits.

    ( Reply )
  37. PG

    james October 20th

    above post translated:

    “I am a nerd and should probably get some fresh air.”

    …and the world continues to function, at least for the rest of us.

    ( Reply )
  38. PG

    Nate Klaiber October 20th

    @Christian
    I am wondering where you are getting that __construct is deprecated? PHP 4 instantiated via the class name, so a class of Article would be function Article(), but PHP 5 has __construct to replace that. I will say that your pastie is much more in line with something being closer to OOP than what he represented, though.

    ( Reply )
  39. PG

    Patrick Sweeney October 20th

    Pretty good tutorial, but why are there all of the extra “extra”’s in the source?

    ( Reply )
  40. PG

    Stefan October 20th

    Good tutorial, but what’s it doing in “News”, shouldn’t it like be in “PHP”?…

    ( Reply )
  41. PG

    Miles Johnson October 20th

    @Christian Dalsvaag – Uh…

    2 – No It IS NOT deprecated. __construct() is the php 5+ of using the constructor where as php 4 is the classname. (class Blog: function Blog()), are you confused here or something? __construct is going no where.

    1 – Yes you dont need curly braces for 1 line if statements, but to me its bad practice. Some setups and servers might not work correctly, ITS ALWAYS best to write clean well formatted code, using shortcuts are simply that… shortcuts which might not work all the time.

    ( Reply )
  42. PG

    Miles Johnson October 20th

    Oh and also your blog class is mediocre at best.

    ( Reply )
  43. PG

    Bogdan October 20th

    Actually, using curly braces for 1 line control structures is considered bad practice, readability actually decreases readability and you get more lines of code/bigger files which is never great.

    ( Reply )
  44. PG

    Miles Johnson October 20th

    Since when is shorthand more readable? If you have tons of code and its all crammed into shorthand code, thats less readable.

    PHP filesize rarely has anything to do with runtime. Especially if its just whitespace/closing statements.

    ( Reply )
  45. PG

    Taylor satula October 20th

    I like the idea. I agree though with the shorthand on this one

    ( Reply )
  46. PG

    Jacob Gube October 20th

    @Christian Dalsvaag
    1. About declaring the scope of the variables – it’s a matter of choice. Some people like explicitly declaring the scope of their variables. It’s up to you/your team’s coding standards.

    2. __construct() is new to PHP 5, so how is it deprecated? http://us2.php.net/manual/en/language.oop5.decon.php

    3. He’s only setting a default value for the two parameters if you initiate a new object without passing parameters.

    5.1 Curly brackets on single-line if’s is also a matter of choice/coding standards. If there was a performance difference, it’s probably negligible. For example, PEAR coding standards encourage you to use curly brackets even when they’re optional to improve readability. http://pear.php.net/manual/en/standards.control.php

    5.2 For an intro-level tutorial, I’d avoid using ternary operators, it would be a pain to explain, but I agree you could see that being re-written into something cleaner (I’d personally consider a switch statement with the default case being the last if – but this is a personal choice).

    A suggestion though, in these tutorials in general, is to adopt a coding standard for all NETTUTS articles. I see Ben using sort of a PEAR coding format, but then it breaks down in the control structure curly brackets i.e.
    if ($whatever)
    {

    }
    instead of
    if ($whatever) {

    }

    to easily distinguish between class and function definitions.

    OOP in PHP is definitely a difficult topic to cover, especially geared towards beginning developers. When I understood OOP, I already had coding experience. so Ben should be commended for tackling such a relatively tough topic (and then to cover classes in PHP as well, ouch).

    If you’re writing a second part of this tutorial – it would be cool to include a database class and further advocate OOP – because in a real blog app, you’ll be connecting, querying, executing, and closing in multiple places, so it’s nice to have a shared resource for it.

    And it would be cool to close the connection (mysql_close($connection)) after you’ve used it (in this case, it could be right before the last ?>).

    ( Reply )
  47. PG

    Jeffrey Way October 20th

    @Stefan – Whoops! Thanks, I’ve fixed it.
    @Michael – It was just a permissions problem. You shouldn’t have any troubles now. :)

    @Christian – Try to relax, man. The way your comments come across, you sound like you have a vein in your forehead that pops out every time you speak. Relax a bit. We’re all here to learn. If you have a better way of getting the job done, I openly invite you to write a tutorial for us. We’ll pay you $150.

    If the community decides that there are things that will make this tutorial better, Ben might be willing to revise it a bit for us. :)

    ( Reply )
  48. PG

    Athens GA Web Design October 20th

    Wow, Another great tutorial! I’ve had a project in mind that I wanted to built my own custom PHP/MySQL layout for, and I have been really stuck on the best ways to construct the classes and the databases. While my project isn’t a blog, this tutorial gave a lot of great insight in how to go about designing your databases and making classes, and makes it a lot clearer.

    ( Reply )
  49. PG

    Lamin Barrow October 20th

    Nice article but i can’t help it but say that, in my won humble opinion, i think that a better title for this post would be “How to create a blog using Object Oriented PHP”.. just makes more sense since there is no way a blog can adapt an OOP design pattern.. but obviously PHP can.

    Thanks for the tut. :)

    ( Reply )
  50. PG

    Christian Dalsvaag October 20th

    I am very sorry that I got the __construct statement wrong. I must have been a lazy reader, then it will be NameOfClass(); that is going to be deprecated. I read some article about it in my studies.

    I know I have a harsh way of writing, but I have been using it ever since I noticed that people actually react, and thinks about it too.

    About the choices of writing shorthand etc. I’m coming from Python, PHP and Ruby – in which Ruby is the latter; and I guess I have been really influenced by the simple beauty of that code. I’ve been trying to teach it away ever since. To me simple code, and less use of brackets etc. is in fact much more readable.

    I try to use if(something): and endif; or i.e while(something): endwhile;. I don’t know if it for someone easier understands what I like to see as messy code, but maybe it really is a matter of choice – and how you interpret it yourselves.

    What I actually loved about making those comments, is that I learned from other developers.

    There will be a lot more comments, and please – answer me as harshly as I comment … people learn.

    I will btw, try to write an article for NETTUTS with my practices – the “Ruby LIKE” ones, but I will be sure to check my references and resources better before I do so!

    Thanks.

    ( Reply )
    1. PG

      Rijad August 27th

      I would really like to know what type of literature your reading on php-dev?

      ( Reply )
  51. PG

    Dav October 20th

    I’m sorry but although I imagine this tutorial was well intentioned, it is a really bad example to follow.

    I admit it looked good at first, I followed the tutorial until the half way point, and then realised… you haven’t even bothered to proof-read your own tutorial!

    You put “first_name” as the people database field, but then try to read it as “$row['firstname']“.

    You read “$row['postfull']” from the database, but you never even told us to put that field into the database at the start?

    You put “tag_id” as the blog_post_tags database field but then use this “blog_post_tags.tagID” in a later query?

    Again as others have spotted, you use public on your class vars for no reason whatsoever, yet you don’t specify the visibility of your methods?

    Also anybody spotted the potential sql injection problems? OK I understand that non of the queries contain untrusted data, but I get the feeling you would have just as easily put a $_GET['*'] in your query and still not added mysql_real_escape_string() for example.

    Oh and “SELECT *” is a very bad habit to get yourself into always use “SELECT field1, field2, field3″, it makes for much cleaner code and your only returning the fields you need!

    I’m sorry Ben if it feels like I have slated your tutorial, but you have to agree its a bad foundation for beginners to learn from, not only will it leave them confused as to why the code they have written following this tutorial won’t work, but it also teaches them bad practices which is probably the reason that a lot of PHP code out there sucks!

    @Christian, since when is __construct or _destruct deprecated???

    ( Reply )
  52. PG

    Nick October 20th

    I’m still having trouble figuring out why all of this needs to be OOP. I see the sense in it for large applications, particularly in compiled languages, but it seems to me this would have been much shorter and quicker to execute if done procedurally. What’s the point in creating a class if you’re only going to use it once?

    Not trying to just be negative, I just honestly need some insight as to what benefit using OOP in small scale applications such as this one is beneficial.

    ( Reply )
  53. PG

    Vince October 20th

    I think this is the wrong way to start people out on the road to OOP. I like PHP but OOP is just bolted on… And without first wrapping your head around the concepts of OOP you’re just going to encourage classes with procedures instead of a true functions.

    Also it makes it easier for you/ your designers to read your “view” if you use nicer php formatting/shorthand:
    (Hopefully this works)

    <?php foreach ($blogPosts as $post): ?>
    <div class="post">
    <h2><?=$post->title?></h2>
    <p><?=$post->post?></p>
    </div>
    <?php endforeach ?>

    try to name your columns a bit nicer, blog_posts.post seems redundant to me. blog_posts.body does not… plus it makes your view read nicer as well…

    $post->title
    $post->body

    How about the database is named ‘blog’ the table is ‘posts’ and the column is ‘body’? Just a thought.

    Im a stickler for things like that just because I’ve debugged rats nests with names like $waffle

    Fun fun.

    ( Reply )
  54. PG

    Vince October 20th

    Also… no love for PDO? ;)

    ( Reply )
  55. PG

    Kevin Quillen October 20th

    Whoa guys, calm down. The premise of this article seems to simply introduce a -new- user/developer in creating a data structure and using simple functions to talk to the database.

    All the nitpicking is kind of unwarranted since the example works – in which case maybe they should step up and do some writing.

    ( Reply )
  56. PG

    Jacob Gube October 20th

    @Christian Dalsvaag
    Yeah, it’s the other way around, this method is/will be deprecated (but this is you’re only option for PHP4 – like I mentioned earlier):
    class Class_Name
    {
    function Class_Name() {

    }
    }

    Which I always felt was kind of unintuitive.

    ( Reply )
  57. PG

    John Downey October 20th

    I’d love to see a series of OOP articles for .NET 2/3.5 that starts very basic, then each subsequent articles can implement more OOP best practices, design patterns, etc.

    ( Reply )
  58. PG

    4CID October 20th

    Nice Article and a Great Tutorial! Thanks

    ( Reply )
  59. PG

    Barttos October 20th

    @Christian Dalsvaag, maybe you are right, i didn’t say what selecting all fields is bad! This is only my opinion, in big projects you really need to list fileds, the code is faster, i write blog for me.

    @Vince, title?> this not work in PHP>5

    ( Reply )
  60. PG

    Billy October 20th

    Fail. Just, fail.

    Its not oop is you only use a constructor and have a getter function OUTSIDE the class.

    I don’t see any sanitization either… XSS/SQL injection much?

    ( Reply )
  61. PG

    Andy Sowards October 21st

    Thanks for the tute, Much needed refresher to OOP.

    OOP Is definitely the catalyst that will enhance the web in the future.

    ( Reply )
  62. PG

    Mário Andrade October 21st

    Great post, excelent for beginners trainning like me.
    Just one request… I don’t know if it’s your intention or not but I would love it if you would do a follow up teaching how to implement a comment system on this and maybe trackback / pingback also.

    keep up the good work

    ( Reply )
  63. PG

    Knossos October 21st

    Its a useful introduction for OOP :) Perhaps not the best way to use OOP, but it gets the foundations out there.

    As a thought, where you loop through your tags you could also use the implode function. Will save you a lot of code. (and stop you having a comma at the start of your tag list)

    ( Reply )
  64. PG

    Designer October 21st

    very well written article… thanks

    ( Reply )
  65. PG

    Kevin Quillen October 21st

    It’s for beginners guys. Perhaps the article vetting process should require language based articles to have a 5 step part? Kind of like books that start you out easy, then revisit the same examples incorporating security, better methods, etc?

    ( Reply )
  66. PG

    Assault October 21st

    It sounds so easy when you just read along :)

    ( Reply )
  67. PG

    ashvin October 21st

    I agree with Lamin. This should be “How to create a blog using OOP PHP”

    Nice article. Thanx. Im tuned for part 2.

    ( Reply )
  68. PG

    Vince October 21st

    @Barttos I’m not sure what your getting at…

    <?=$foo->bar?> is a shortcut for bar; ?> which is enabled in php.ini, Which is in PHP5, who still uses PHP4 anyways? and why would you.

    ( Reply )
  69. PG

    Vince October 21st

    Whoops.

    <?=$foo->bar?> is a shortcut for <?php echo $foo->bar; ?>

    ( Reply )
  70. PG

    Barttos October 21st

    Vince, i know! and i wrote what this shortcut not work in PHP>5, in PHP 6 you can’t use it!

    ( Reply )
  71. PG

    Miles Johnson October 21st

    @Vince – Its bad practice to use <?= compared to <?php echo. <?= is not supported on all servers and environments and will be deprecated in PHP 6, better stop using it.

    ( Reply )
  72. PG

    matt October 21st

    This is not bad. I think the title should be, “building an OO article list in PHP”. The word blog means there would be much more functionailty.

    For a beginner this is a great way to get your head around some basic OOP practices.

    Nice.

    ( Reply )
  73. PG

    Barttos October 21st

    @Miles, @Barttos: Damn!

    fiiiiiine. ;)

    ( Reply )
  74. PG

    Bleyder October 22nd

    Great tutorial. This is JUST what I was looking for… but perhaps it should be implemented using the Model-View-Controller pattern.

    ( Reply )
  75. PG

    Angelo R. October 23rd

    In general, if you’re going to be declaring the scope of your variables, wouldn’t it be best if they were private?

    That way a set_variable(); method could be introduced which would check the validity of your input. For example, setting the post id to a string could be avoided, as well, it would make debugging random errors a bit easier.

    Maybe I am mistaken, but the very point of OOP lends itself towards reusable code, either by yourself or by someone else, and that to me means that it needs to be as fool proof as possible.

    As to those touting a lack of security features, this isn’t so much a tutorial on how to secure a blog system, as it is a glimpse into the workings of Object Oriented Programming and how it would apply to a real-life situation.

    ( Reply )
  76. PG

    dai October 25th

    Great!
    Wow!
    Thanks to delicious, it will be saved for me!

    ( Reply )
  77. PG

    Anthony Bruno October 28th

    How about some user authentication?

    ( Reply )
  78. PG

    Andy October 30th

    Very good tutorial! Thank you!

    ( Reply )
  79. PG

    sohel364 October 31st

    So clear and perfect for learning something.Thanx

    ( Reply )
  80. PG

    Busby November 1st

    P – E – R – F – E – C – T ! ! !

    ( Reply )
  81. PG

    Igor Mattos November 4th

    Superb!
    Is that part 2 coming soon?
    Can’t wait for that :)

    ( Reply )
  82. PG

    M.A.Yoosuf November 5th

    it gave me a concept of OOP, tks buddy

    ( Reply )
  83. PG

    Illurbabbisub November 7th

    The good convenient site is made.

    ( Reply )
  84. PG

    unmactmub November 8th

    Your site pleased me, will more frequent call

    ( Reply )
  85. PG

    guambupamodia November 8th

    Hello! Excellent site! Searched a long ago

    ( Reply )
  86. PG

    briemoplerb November 13th

    The good convenient site is made.

    ( Reply )
  87. PG

    kadeaffor November 13th

    god site. Continue also

    ( Reply )
  88. PG

    grrrrrr8 November 30th

    AWSOME

    ( Reply )
  89. PG

    Mark December 11th

    God that looks painful for what should be really easy to do… I’m really not certain that the class simplifies things one little bit. All you had to do was

    while($row = mysql_fetch_assoc($result)) {
    echo $row['first_name']; // etc
    }

    And then you’re going to write a class for every single table by hand, right? Either do it the simple way, or grab a framework like CakePHP if you want classes.

    ( Reply )
  90. PG

    مولانا December 17th

    great….
    very thanks

    ( Reply )
  91. PG

    Prabin Karmacharya January 13th

    Great Article! keep it up

    ( Reply )
  92. PG

    owain Llewellyn January 13th

    I’m just started out learning Php and thought I’d give this a go. but im getting the following error:

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/creative/public_html/includes/includes.php on line 25

    I have set up the tables and uploaded the files on the server, I’m not trying to pull the information into the template but keep getting this problem..

    anyone know why this might be happening..

    line 25 is as follows: while ($row = mysql_fetch_assoc($query))

    ( Reply )
  93. PG

    owain Llewellyn January 13th

    sorry the third paragraph after the first comma should read “I AM” trying to pull the information from the database into a template….

    thanks

    ( Reply )
  94. PG

    kailas January 19th

    Good work.Very Thanks

    ( Reply )
  95. PG

    SweetOpium January 22nd

    Simple, nice ;)

    ( Reply )
  96. PG

    sidd February 5th

    it is good,but i think u can make batter,can u plz send me some complete blog as a project

    ( Reply )
  97. PG

    michael February 10th

    A Tutorial how to get entries into the database would be nice.
    Something like a tiny “admin CP”

    ( Reply )
  98. PG

    Mohamed Aslam February 11th

    Excellent tutorial..!

    ( Reply )
  99. PG

    Ian February 23rd

    Great tutorial however i am a little unsure of how i would implement these two features

    1. Have a tag list which will allow users to filter blog posts by a tag

    2. have a months list allowing users to filter posts by month

    3. breaking down blog posts into pages, say 10 blog posts per page

    if someone could help me that would be really great. I have a little knowledge of php and mysql.

    THANK YOUUUUUUUUUUUUUUUUUUUUUU

    ( Reply )
  100. PG

    Nick February 25th

    Great Tutorial, thanks!

    I was wondering if part 2 is already out there? Or is part 2 only readable for members?

    ( Reply )
  101. PG

    James Woods February 28th

    Awesome Tutorial, I look forward to the next one in this series.

    ( Reply )
  102. PG

    toust March 9th

    :( error…
    Catchable fatal error: Object of class BlogPost could not be converted to string in C:\Web\www\newblog\index.php on line 277

    Can you help me?

    ( Reply )
  103. PG

    Angel March 15th

    When you will release the next one?

    ( Reply )
    1. PG

      Jonathan Cousins March 17th

      Me want next one!

      ( Reply )
  104. PG

    Drew March 24th

    I’m new to OOP (coming from C background) but even I see this as a flaw in design pattern. This is a great tutorial for beginners but its not really OOP, if you have a loose function then its not a method and it sure ain’t part of the class. In essence, there is no “true” interface here and I think Christian is correct in his observations, except for not realizing php5 using __construct() and not name of class as the class constructor.

    ( Reply )
  105. PG

    Syzo March 24th

    Currently getting

    Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in /nfs/c02/h06/mnt/41150/domains/benmillsdesigns.com/html/SimpleBlog/includes/blogpost.php on line 6

    Any ideas?

    ( Reply )
  106. PG

    LinkBuilderZ April 13th

    great tutorial! i am a beginner of this database and php World. I am trying to learn all these things. though its a lil hard for me to grab this tutorial yet but still the simplicity of tutorial makes me understand what actually gonna happen. I will try it asap. :) and your that tutorial regarding understanding databases helps me alot in understanding the topic.

    ( Reply )
  107. PG

    Sohail Ahmed April 13th

    This is great.. I’m going to try it.

    ( Reply )
  108. PG

    Michael April 18th

    Brilliant tutorial guys!

    I’d be keen to see if there’s a Registration / Login script that I could use with this. Also possibly an extension to allow the Admin to create normal pages on the site, outwith the blog.

    ( Reply )
  109. PG

    SneManden April 18th

    So many have asked this question:
    WHEN WILL THE NEXT RELEASE COME?

    I haven’t seen any answers to it, so please somebody who have that information on hand, say when, cause some of us can’t wait for part 2

    ( Reply )
  110. PG

    yanz April 20th

    This tutorial is very useful to those who’s just starting up on making there own blog, like me. Thanks Mr. Ben Mills.. Hope to see more of your tutorials..

    ( Reply )
  111. PG

    shaji May 5th

    good and nice article

    ( Reply )
  112. PG

    Jules Manson May 13th

    Thanks for this tutorial. I am a beginner in PHP and hope to one day become a PHP “rockstar.” But until then I shall continue to ask the questions that I cannot determine the answers to on my own. I am running WAMP 2 on my windows Vista. WAMP 2 has PHP 5.2.9-1 and MySQL 5.1.32 and Apache 2.2.11. I downloaded the source code and installed everything and everything seems to work except for these errors I get for the top post (I believe). All other posts work fine.

    Notice: Undefined index: postfull in C:\wamp\www\nettutsblog\includes\includes.php on line 27

    Notice: Undefined index: dateposted in C:\wamp\www\nettutsblog\includes\includes.php on line 27

    Notice: Undefined index: postfull in C:\wamp\www\nettutsblog\includes\includes.php on line 27

    Notice: Undefined index: dateposted in C:\wamp\www\nettutsblog\includes\includes.php on line 27

    Notice: Undefined index: postfull in C:\wamp\www\nettutsblog\includes\includes.php on line 27

    Notice: Undefined index: dateposted in C:\wamp\www\nettutsblog\includes\includes.php on line 27

    Please email me if you find out what is wrong with it.

    Thanks

    ( Reply )
  113. PG

    SEO Consultant May 29th

    Nice work dude… It is helpful for me as well as others..

    ( Reply )
  114. PG

    Saulo June 24th

    Very good.
    Helped me a lot.
    Thanks!

    ( Reply )
  115. PG

    nateOn July 3rd

    how can i post..?? i already made no error but one thing I ask how can i post blog without button to click, im sorry but im newbie, can somebody tell ne how to?

    ( Reply )
  116. PG

    Geet prasad July 13th

    whai i want i got 4m ur tutorial……thanxxxxx

    ( Reply )
  117. PG

    Swenflea July 13th

    How do you post new blogposts?
    Any help would be great!!

    P.S. PHP is just one big mess to me!!!

    ( Reply )
    1. PG

      Eric November 18th

      This posts provides no methods for doing so. It’s a pretty worthless approach to OO programming, and blogging for that matter…

      ( Reply )
  118. PG

    Tara July 22nd

    I get errors…..

    Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/a6964267/public_html/Template/SimpleBlog/includes/includes.php on line 20
    line 20 is…….
    $query = mysqli_query(”SELECT * FROM blog_posts ORDER BY id DESC”);

    Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /home/a6964267/public_html/Template/SimpleBlog/includes/includes.php on line 24
    line 24 isss….
    while ($row = mysqli_fetch_assoc($query))

    any help or suggestions?

    ( Reply )
  119. PG

    Carlos July 26th

    Hello. Im ready for step 2. I did follow all your tutorial, but now I need the forms and link to people to post. No idea how to do it. Can you give me any update about when the step 2 will be available? thanks so much.

    ( Reply )
  120. PG

    Dean July 30th

    This is great ive been looking for a tutorial that shows how oo php is used in projedts effectivly and this has certainly done that for me Thanks.

    ( Reply )
  121. PG

    Jitendra July 31st

    this is tha amazin tutorial

    thanks for the help

    ( Reply )
  122. PG

    Jimmi August 1st

    Still waiting for part 2

    ( Reply )
  123. PG

    jeremiah August 2nd

    The blog is down, I wouldn’t count on part 2. Looks like this guy is a flake

    ( Reply )
  124. PG

    ichigo uzumaki August 14th

    dowmload source??
    this the great tuto!!!
    i waana student php POO
    excuseme…
    the second part??
    i wanna write from form to php !!!

    ( Reply )
  125. PG

    Hugo August 19th

    When will the second tut be out?

    ( Reply )
  126. PG

    Ubon Asanga August 24th

    Its great to find this forum. I am just starting to code php but then i am having fun. you guy i need your help

    ( Reply )
  127. PG

    Swenflea September 12th

    How would you make it that when there are say 3 posts on a page it would have a link down the bottom/top of the page saying “Older Posts” or somthing like that.

    Like what net.tutsplus.com has with the links to all the pages.

    Thanx.

    ( Reply )
  128. PG

    sanjeev September 15th

    hi this is cool

    ( Reply )
  129. PG

    little_oak September 22nd

    Very Nice!

    ( Reply )
  130. PG

    ghprod November 13th

    wow .. hot comments in here :)

    calm down everyone :)

    thanks Ben for sharing …. regards

    ( Reply )
  131. PG

    Ahsan November 16th

    Read’d all the comments, finally i want to say “People, what ever someone does, it teaches you something, use your mind to full extend. Never just depend on others, it was just a tutorial not a real big script for you to start your commericial website, so stop behaving like u didn’t got to it!” Use MIND …. its ur best frnd!!….

    best of luck and @Christan, man you are a havoc……. Think before u say sumthing!! .

    ( Reply )
  1. Arrow
    Gravatar

    Your Name
    November 16th