PEAR Articles

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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    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

    blog comments powered by Disqus

    PEAR ARTICLES ARTICLES

    - Installing PEAR
    - PEAR: an Introduction
    - Managing robots.txt using PHP: Generating Dy...
    - 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


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