Miscellaneous
  Home arrow Miscellaneous arrow Page 2 - Creating a News System with PHP - Part...
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
MISCELLANEOUS

Creating a News System with PHP - Part 2
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2002-03-11

    Table of Contents:
  • Creating a News System with PHP - Part 2
  • Adding Options to the Display
  • Deleting an Item
  • Editing an Item
  • The Final Product

  • 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


    Creating a News System with PHP - Part 2 - Adding Options to the Display


    (Page 2 of 5 )

    The first thing we need to do is add links next to each news item so that we have a way to tell the script we want to edit or delete the item. So, let's get to adding those links.

    For the administrative script, I really don't care if the newest news is first. In fact, I would rather have the oldest news first. It just makes things easier. So, remember where we used the array_reverse function? Well, I'm just going to take it out for this administrative script.

    Now that we have the news in the order of oldest to newest, let's add some links for delete and edit next to the "Posted by" line of each item. We are going to need to have a way to address each news item. We already have the information in an array, and there is a key associated with that array. So, why don't we just use that? In order to use the key, we need it defined somehow. The following change will allow us to use the key.

    <?php
    foreach($data as $element) {

    should be changed to:

    foreach(
    $data as $key=>$element) {
    ?>

    Now that we have the key, we can add a unique URL for each news item to delete or edit it. Simply make the following change.

    <?php
    echo $pieces[2] . "&lt;BR&gt;" "&lt;b&gt;Posted by " $pieces[1] . " on " $pieces[0] . "&lt;/b&gt;&lt;BR&gt;&lt;BR&gt;";

    should be changed to:

    echo 
    $pieces[2] . "&lt;BR&gt;" "&lt;b&gt;Posted by " $pieces[1] . " on " $pieces[0] . "&lt;/b&gt;\n";
    echo 
    "&amp;nbsp;&lt;a href=\"$PHP_SELF?action=delete&amp;id=$key\"&gt;Delete&lt;/a&gt;\n";
    echo 
    "&amp;nbsp;&lt;a href=\"$PHP_SELF?action=edit&amp;id=$key\"&gt;Edit&lt;/a&gt;\n";
    echo 
    "&lt;BR&gt;&lt;BR&gt;\n";
    ?>

    This is going to give us two links after each "Posted by" line that will allow us to delete and edit news.

    More Miscellaneous Articles
    More By Matt Wade


       · need an html output to see exactly what is happening
       · it is really annoying
       · Just a note that the final product doesn't show up in the pdf, so if you print out...
       · How would I make it post news from newest to oldest?
       · Forget I ever posted that, I didn't read through the whole thing. It says it in the...
       · I've gone through this tutorial and updated the HTTP_POST_VAR to $_POST and I can...
       · I've been playing with the code and just can't seem to get it to work. I kept...
     

    MISCELLANEOUS ARTICLES

    - Using PHP to Stream MP3 Files and Prevent Il...
    - 10 Must Have Firefox Improvements
    - All About OpenOffice 3.0
    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell
    - Data Streams and the UNIX Shell
    - Control Mechanisms of the UNIX Shell
    - Variables Within the UNIX Shell
    - The Shell and UNIX
    - In Detail: UNIX File Systems
    - Rights Management in UNIX
    - UNIX File Systems
    - The Terminal in UNIX
    - Operating Systems and UNIX





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT