Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - Creating a News System with PHP - Part...
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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    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

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


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