Article

Home » Server-side Coding » PHP & MySQL Tutorials » Diary of A Webmaster Part 2 - Create a Content Feed

About the Author

Mitchell Harper

author_mitchellharper Mitchell is the co-founder and product manager at BigCommerce—SaaS ecommerce software which is used by thousands of businesses to sell online. He can be reached via email at mitch@bigcommerce.com

View all articles by Mitchell Harper...

Diary of A Webmaster Part 2 - Create a Content Feed

By Mitchell Harper

February 5th, 2002

Reader Rating: 9

Page: 1 2 3 Next

So, you've spent the better part of a year creating your PHP/MySQL driven Website. You've got a reasonable amount of decent, flexible content, and you're buddies with a couple of other Webmasters, so they've given you a free banner ad on their site in exchange for one on yours. What else can you do to promote your pièce de résistance?

A site's promotion can be even more difficult than its development. I've found that one of the best ways to attract more visitors to your site is to share your content with whoever wants it. That's right; let them publish your articles on their site (as long as they add a link back to your site near the end), write articles specifically for other Websites and ezines (hey, I'm doing that now aren't I?), and set up a content feed from your site.

Just last week I set up a content feed similar to the one I'll describe in this article. What's that you say? "How do I set up a content feed? I only know PHP and MySQL!" Never fear -- in this article I'll show you how easy it is to set one up. But first, let's discuss why you'd want to set up a content feed for your site.

Why A Content Feed?

I've said it before and I'll say it again: if your site's going to succeed on the Net, it needs to contain useful, free content targeted directly at a niche market.

Take a look at some of the most popular sites on the Web: ZDNet, Slashdot, Cnet, MoreOver, etc. All of these sites provide dynamic content feeds that anyone can use on their site, so that if I wanted to display their recent news headlines on my site, I would simply have to fill in a form and paste some HTML tags on my site, and I'd be done.

If Joe Bloggs posts the HTML code for ZDNet's content feed on his site, then it's a win-win situation: Joe provides valuable news to his visitors, which keeps them coming back on a daily basis, and ZDNet benefits from increased traffic when Joe's visitors click on the news headlines to see the full story on their site.

A few reasons why you should consider creating your own content feed include:

  • It's one of the best forms of free advertising.
  • Once other people post your content feed on their site, each headline actually links back to the full article your site. As many of you will know, the more links you have back to your site from other sites, the higher search engines such as Google will position you in their rankings.
  • Obviously, having others post your content feed on their site will boost your traffic. By how much your traffic will increase depends on the quality of your content and how well you formulate your headlines.

Hopefully by now I've convinced you to set up a content feed. Let's take a look at creating a sample content feed using some PHP and a MySQL database.

Creating a Sample Content Feed

One of the reasons why content feeds are so popular is because 99% of the time, all you need to do to include someone else's content feed on your site is add a reference to an external JavaScript file using a HTML <script> tag, like this:

<script language="JavaScript" type="text/javascript"  
src="http://www.jb-news.com/feed.php"></script>

Let's assume that I run a small Website and want to publish Joe Bloggs's content feed on my site using the code above. In it, I've set the src attribute to a file named feed.php on Joe's Website (and not a typical JavaScript file that ends with .js).

This isn't a problem, however, because both IE and Netscape don't care what the file extension is, provided that, when the file is grabbed, it actually contains valid JavaScript code. Let's create a sample content feed now. To start with, load the MySQL console application and create a new database named content:

create database content;
use content;

Next, create a new table named articles. This table will contain all our news items:

create table articles
(
 articleId int auto_increment not null,
 title varchar(100),
 content text,
 primary key(articleId)
);

The table we've just created should be pretty self-explanatory. It contains three fields:

  1. articleId, an integer which is also a primary key and unique identifier,

  2. title, which will contain the headline of each news item, and

  3. content, a text field that will contain the body of each news item.

Let's add three news items to our articles table using these MySQL commands:

insert into articles values(0, 'PHP scripting language takes  
world by storm', 'It was announced today that at least two  
million web sites around the world are using the PHP and  
MySQL language/databasing technique to create  
sites that are flexible');

insert into articles values(0, 'Linux includes G++ compiler',  
'Linux, one of the world\'s most popular operating systems,  
also includes a copy of both the GCC and G++ compilers, which  
allow you to compile C/C++ program easily from the  
command line');

insert into articles values(0, 'Microsoft announces C#',  
'Microsoft have today announced that its new .NET framework  
will be based around a language named C# (pronounced  
C-Sharp). This language is much like C++ but is designed  
for modern prorgammers');