MySQL
  Home arrow MySQL arrow Page 3 - Creating the Blog Script for a PHP/MyS...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Creating the Blog Script for a PHP/MySQL Blogging System
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 23
    2006-10-10

    Table of Contents:
  • Creating the Blog Script for a PHP/MySQL Blogging System
  • The Database Tables
  • index.php
  • comments.php

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!

    Creating the Blog Script for a PHP/MySQL Blogging System - index.php


    (Page 3 of 4 )

    When the "index.php" is loaded the following SQL is executed:

    <?
    include "config.php";
    $query1="Select *,DATE_FORMAT(date_posted,'%W,%d %b %Y') as
    thedate FROM article INNER JOIN categories ON categoryID=catid
    WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY)AND artchild='0' ORDER
    BY date_posted DESC LIMIT 10 ";
    $blogarticles = mysql_query($query1) or die(mysql_error());
    $num = mysql_num_rows($blogarticles);
    ?>

    In this SQL the articles are retrieved together with the categories to which they belong. The inner join does the job of linking the articles with their categories. The DATE_SUB() function does the job of retrieving all the messages posted in the last thirty days.

    I set the condition of "artchild=0" because any article whose "artchild" value is greater then zero is a reply. All replies have the same title as the main article to which it is replying. By putting a condition of “0” in the SQL, I only retrieve the main topics. You will be able to view comments made to these topics by clicking on a link called comments, which is displayed with each topic.

    To work out whether comments have been made on an article, we run the following SQL:

    $getcomments = "SELECT * FROM article WHERE
    artchild='".$row_articles['artid']."'";
    if(!$theResult=mysql_query($getcomments)){
    echo mysql_error();
    }else{
    $num_comments=mysql_num_rows($theResult);
    echo $num_comments;
    }

    The ‘".$row_articles['artid']."’ refers to the article ID retrieved from "$query1." Then we just count the number of rows returned as in the line "$num_comments=mysql_num_rows($theResult);" and display that number.

    If you look towards the right in the screen shot below, you will notice a list of topics displayed. This is achieved by the following SQL:

    $query="Select *,COUNT(*) FROM article INNER JOIN categories ON
    categoryID=catid WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) GROUP
    BY title DESC LIMIT 10 ";
    $blog = mysql_query($query) or die(mysql_error());
    $num_blog = mysql_num_rows($blog);

    Again this SQL just retrieves the articles from the database and joins the category information on the articles. We need the category info because we are going to show the title of the articles and in what category they were posted.

    Here’s a screen shot of the index page:

    More MySQL Articles
    More By Jacques Noah


       · In this day and age, can't we post proper tutorials for people who want to get...
       · Just like anything else, you have to learn the basics before you refine your skills....
       · Please check the disclaimer; the whole idea of my articles is to provide a very...
       · I found the the article extremley useful as an exmaple of basic mysql and php...
     

       

    MYSQL ARTICLES

    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...
    - Creating the Blog Script for a PHP/MySQL Blo...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway