PEAR Articles
  Home arrow PEAR Articles arrow Page 3 - Creating the Main Pages of a PEAR CMS
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

Creating the Main Pages of a PEAR CMS
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-10-29

    Table of Contents:
  • Creating the Main Pages of a PEAR CMS
  • Code Explained
  • More Code
  • Run the Query

  • 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 the Main Pages of a PEAR CMS - More Code


    (Page 3 of 4 )

    Note that the display of the last section in the navigation panel is dependent upon whether or not the currently logged-in user has an administration level clearance. This link will give administrators of the system access to the administration portal of the site, so we do not want just anyone to enter that portal.

    Basically, the code here checks to see if the session variable that stores the access level of a user is set to admin. If it is, a link to the admin section is displayed; otherwise, it is not:

    <?php if($_SESSION['level']=="admin"){?>

    <tr class="navbord">

    <td colspan="2" class="nav"><a href="admin/index.php">Admin</a></td>

    </tr>

    <?php }?>

    </table>

    Once the code has determined whether or not a user is an admin, it takes the necessary action and closes the table.

    The next part of the code is responsible for extracting the latest five articles from the database. It uses the DB functions to achieve this. First, the script calls the db class. This is necessary because we need to use the methods of this class to access and manipulate the database information. Then the connx.php file is included -- we need the database connection credentials which are stored there:

    <?php

    include 'db.php';

    include 'connx.php';

    Next we run a slightly complex query to retrieve the latest articles. The query is complicated because the information that we want is contained in two different database tables. This information is of course linked, as explained in the first article of the series. The actual article is located in a database table called “stories.” It has all the different parts that make up an article. The author information is stored in the authors table.

    What we want the query to do is retrieve all the articles that are related to a particular author, so we literally have to join the two tables to extract this information. This is where the INNER JOIN function of MySQL comes in. This function links the foreign key in the stories table to the author ID in the authors table. Then, it accurately retrieves all the articles that are related to a particular author:

    //retrieve the latest 5 stories, include the author names as well. Store the record

    $sql = "SELECT * FROM stories INNER JOIN authors ON stories.author=authors.aid

    order by s_date asc limit 5";

    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
    For more Enterprise Application Development news, visit eWeek