PEAR Articles
  Home arrow PEAR Articles arrow Page 3 - Deleting Authors from a PEAR Content M...
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? 
PEAR ARTICLES

Deleting Authors from a PEAR Content Management System
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-12-03

    Table of Contents:
  • Deleting Authors from a PEAR Content Management System
  • Code Explained
  • Extracting Database Information
  • Adding Authors

  • 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


    Deleting Authors from a PEAR Content Management System - Extracting Database Information


    (Page 3 of 4 )


    This part of the code is at the heart of the page. It is responsible for extracting the needed database information. In order for this code to use any kind of database abstraction, it requires the DB classes. The methods contained in the class are what we will use to interact with the database server and tables.

    Our main aim is to get a list of author names as well as their author IDs. Since we know that the authors database table has only two fields, we construct a simple query that retrieves all the fields from the table, and then run it using the DB’s query() function. If the table had contained more then two fields, we would have had a SQL query that looked something like this:

    $sql=”SELECT aid,name FROM authors”;


    instead of


    $sql=”SELECT * FROM authors”;

    The reason for this is that we require only two fields; retrieving any other fields would just slow down the data extraction process. To make the DB class and its methods available to our script, we include the DB.php file. Now, to make those methods and function useful, we need the database connection details. These are contained in the connx.php file. So we include the connx.php file:


    <table width="100%" border="1">

    <?php

    include 'db.php';

    include 'connx.php';

    We then run the SQL code that is required using DB’s $db->query() function and store the returned rows in a variable called $res:

    $sql = "SELECT * FROM authors";

    $res = $db->query($sql);

    The next thing we do is test the $res variable to see if it actually contains any values. So we run a conditional check, and if the variable contains any data we run a while loop. The while loop will iterate through the results set and lists the name of the author together with the delete option. All of this is displayed in a dynamic table whose rows are created as the records are retrieved:


     

    if($res){

    while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {

    ?>

     

    <tr>


    <td width="25%" class="auth"><a href="authart.php?aid=<?=$row->aid?>" class="auth">$row->name</a></td>

    <td width="75%" class="auth"><a href="delete.php?aid=<?=$row->aid?>">Delete</a> </td>

    </tr>


    Notice that when the rows are retrieved, links to the authart and delete scripts are created.

    Along with these links is included the author ID, which will be used by the relevant script to either delete or retrieve information based on that ID:


    <td width="25%" class="auth"><a href="authart.php?aid=<?=$row->aid?>" class="auth">$row->name</a></td>

    <td width="75%" class="auth"><a href="delete.php?aid=<?=$row->aid?>">Delete</a> </td>


    If the $res variable does not contain any records, then the code displays a message stating that it did not find any authors in the database:


    <? }

    }else{

    ?>

     

    <tr>

    <td colspan="3" class="maintxt"><p class="auth">No authors found</p></td>

    </tr>

    <? } ?>

    </table>


    The HTML table is then closed and the HTML for the page is also closed.


    <!-- InstanceEndEditable --></td>

    </tr>

     

    <tr class="copy">

    <td colspan="2">&copy;2008</td>

    </tr>

    </table>

    </body>

    <!-- InstanceEnd --></html>

    More PEAR Articles Articles
    More By David Web


     

    PEAR ARTICLES ARTICLES

    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR





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