PEAR Articles

  Home arrow PEAR Articles arrow Page 4 - Building an Authors Page for a PEAR CM...
PEAR ARTICLES

Building an Authors Page for a PEAR CMS
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-11-12

    Table of Contents:
  • Building an Authors Page for a PEAR CMS
  • The Code Explained
  • HTML Table
  • Extracting Author Information

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Building an Authors Page for a PEAR CMS - Extracting Author Information


    (Page 4 of 4 )

    Next, the code runs a simple query that extracts all the author information from the authors database table:

    $sql = "SELECT * FROM authors";

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

    The results of this query are stored in the $res variable. The variable is then tested to see if any records have been found. If records are found, the code continues to run the while loop.

    if($res){

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

    ?>

    The while loop retrieves all the records while at the same time building dynamic rows that will accommodate the author names as they are retrieved. Also note that a link to the authart page is created with a query string that passes a author id to that page: 

    <tr>

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

    </tr>

    If the $res variable does not contain any records, the code shows an appropriate error message and closes the table:

    <?php }

    }else{

    ?>

    <tr>

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

    </tr>

    <?php } ?>

    </table>


    Then the HTML page is closed:


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

    </tr>

     

    <tr class="copy">

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

    </tr>

    </table>

    </body>

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

    The next page that we are going to look at is the authart.php page. It is responsible for showing all the articles written by a particular author. The code that is at the heart of this script is something like this:

    <?php

    include 'db.php';

    include 'connx.php';

    if(isset($_GET['aid'])){

    $aid=mysql_real_escape_string($_GET['aid']);

    }

    $sql = "SELECT * FROM stories WHERE author='".$aid."'";

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

    if($res){

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

    ?>

    <tr>

    <td class="title"><a href="view.php?sid=<?php print $row->sid?>" class="title"><?php print $row->title ?></a></td>

    </tr>

    <?php }

    }else{

    ?>

     

    <tr>

    <td colspan="2" class="auth"><p class="auth">No articles found</p></td>

    </tr>

    <?php } ?>

    </table>


    The code above simply retrieves the articles from the stories table that belong to the author with the given ID. These articles will then be listed in the HTML table that is constructed by the while loop. I will discuss this code in more detail in the next article. 


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    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 6 - Follow our Sitemap