PHP and MySQL Code

Start typing to search for PHP and MySQL Code Snippets and Articles Search

Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder

Go Back Add a Comment Send this Article to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
Title : PHP and MySQL News with Comments
Categories : PHP, Databases, MySQL
Date : 2003-09-20
Grade : 5 of 5 (graded 1 times)
Viewed : 19571
Search : More Articles by codewalkers
Action : Grade This Article
Tools : My Favotite Articles

Submit your own code examples 


Some time ago, I wrote two tutorials about creating a news system. Both of those tutorials dealt with using flat files as the method of storage. Today, we will investigate the use of a database backend, specifically MySQL.

Before we get started, I want to talk a little about my idea of tutorials. When I write a tutorial, it is not my goal to produce a complete working piece of code. Sure, a lot of times there will be a final product that you could use, but why would you want to when you can write your own code? The tutorials I write I meant to introduce concepts and new ideas to you. Maybe show you some aspect of PHP that you didn’t know about.

So, all I ask is that you don’t skip to the last page of this tutorial and snap the code and expect it to solve all your problems. Read through the tutorial and incorporate the ideas given here with your own and you will have a much better final product.

Let’s talk a minute about the concepts behind making a news system with PHP and MySQL. First off, the primary goal is to display news. So, the code should, before it does anything else, display news. On the backend, we will have a table to store all this news. We should probably store the news itself, a title for the news, and a date the news was published. Along with that, we will also have a unique id for each piece of news.

The next thing we want this system to do is allow users to comment on the news we post. We will store these comments in a table separate from the news. The reason for this is that you can have multiple comments per every news item. In database relationships, this is called a “one to many relationship”. In the comments table, we will want to store the comment itself, the name of the user, and the news id that it is associated with. We will also store a unique id for each comment.

The whole key to adding comments to a news system is to store the news id along with every comment. Without storing the news id, you would have no way to relate the comment back to the proper news item.


Referer Statistics
Categories : PHP, MySQL, HTTP, Databases
Descriptions of Common Data Types
Categories : MySQL, Databases, PHP, PHP options/info, General
Beginners guide to PHP and MySQL
Categories : PHP, Beginner Guides, Databases, MySQL, Installation
PHP, MySQL and Authentication 101
Categories : PHP, Databases, MySQL, Authentication
Creating an IE-Only Database Driven Menu System With PHP, MySQL and DHTML
Categories : PHP, MySQL, Databases, DHTML
Building A Persistent Shopping Cart With PHP and MySQL
Categories : PHP, MySQL, Databases, Ecommerce
Case Study: Handling MySQL Growth With a PHP Class
Categories : Databases, MySQL, PHP
Practical Date and Time examples with PHP and MySQL
Categories : Databases, MySQL, PHP, Date/time
Simple Connection to MySQL with PHP
Categories : PHP, MySQL, Databases
Miles To Go Before I Sleep...
Categories : PHP, Calendar, Databases, MySQL
Alternating row colors with PHP and mySQL
Categories : PHP, Databases, MySQL, HTML and PHP
Multicolumn Output from a Database with PHP
Categories : PHP, Databases, HTML and PHP, MySQL
Date Arithmetic With MySQL
Categories : PHP, Databases, MySQL, Date Time
Time Is Money Part 1 of 2 - Designing and implementing a Web-based application
Categories : PHP, Databases, MySQL, Complete Programs
Building a Quick and Dirty PHP MySQL Publishing System
Categories : PHP, Databases, MySQL