Database Articles

  Home arrow Database Articles arrow Page 5 - PHP/MySQL News with Comments
DATABASE ARTICLES

PHP/MySQL News with Comments
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2002-09-03

    Table of Contents:
  • PHP/MySQL News with Comments
  • The Tables
  • Displaying the news
  • Displaying the comments
  • Displaying one item with comments
  • Adding comments
  • Summing it up and final script

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    PHP/MySQL News with Comments - Displaying one item with comments


    (Page 5 of 7 )

    So, we have displayed all the news and we have displayed the comments. We need to tie it together. When a user clicks on the comments link from the main news page, we need a way to display the single news item with the comments. To do that, we will query the news table for the id of the news item we are looking for and display that news. Then, we will simply call the displayComments function to show the comments.

    <?php
    function displayOneItem($id) {
        global 
    $db;
        
        
    /* query for item */
        
    $query "SELECT * FROM news WHERE id=$id";
        
    $result mysql_query ($query);
        
        
    /* if we get no results back, error out */
        
    if (mysql_num_rows ($result) == 0) {
            echo 
    "Bad news id\n";
            return;
        }
        
    $row mysql_fetch_assoc($result);
        echo 
    "&lt;TABLE border=\"1\" width=\"300\"&gt;\n";

        
    /* easier to read variables and 
         * striping out tags */
        
    $title htmlentities ($row['title']);
        
    $news nl2br (strip_tags ($row['newstext'], '&lt;a&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;'));
        
        
    /* display the items */
        
    echo "&lt;TR&gt;&lt;TD&gt;&lt;b&gt;$title&lt;/b&gt;&lt;/TD&gt;&lt;/TR&gt;\n";
        echo 
    "&lt;TR&gt;&lt;TD&gt;$news&lt;/TD&gt;&lt;/TR&gt;\n";
        
        echo 
    "&lt;/TABLE&gt;\n";
        echo 
    "&lt;BR&gt;\n";
        
        
    /* now show the comments */
        
    displayComments($id);
    }
    ?>

    More Database Articles Articles
    More By Matt Wade

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap