PHP
  Home arrow PHP arrow Page 3 - Developing Multipurpose Pages With PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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? 
PHP

Developing Multipurpose Pages With PHP
By: Unknown User
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2002-10-11

    Table of Contents:
  • Developing Multipurpose Pages With PHP
  • Multipurpose Web Pages
  • Examining The Code
  • Conclusion

  • 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


    Developing Multipurpose Pages With PHP - Examining The Code


    (Page 3 of 4 )

    First, the script checks if there is a username and password being passed through a form via the HTTP POST method. If there is none, the script will display the code that will prompt for a username and password.

    If they are present then the script will run queries on the database to check if a valid username and password combo was used. If it is, then the script will display the message "Welcome, $name!", otherwise it'll display an error and prompt the user again.

    As I said earlier, multipurpose pages use control structures to choose one of many possible 'templates' to generate a specific, and yet dynamic, page. When using forms, which I have seen to be the most common element used with multipurpose, you can easily implement if/else to display either the form, or the result text.

    Multipurpose can also be used to create forums with GET values instead of POST values. This enables you to create links instead of forms that will get you to a certain version of one page. Although not evident until forums are made, a multipurpose page can be in any number of parts, not just two.

    Multiple (3+) parts allows for multiple forms, or in the case of forums, a forum ID, a thread ID, and a message ID. Other values can also be tagged on. This increases information-gathering capabilities, and continues to cut down on number of pages and overall space taken up on servers.

    A Practical Example
    Here's an example of a multipurpose web page. See if you can figure out what it does:

    <?PHP
    $forum = $_GET['forum'];
    if (!isset ($forum) ) {
    $sql = "SELECT forums, ID FROM master_list";
    $get_forums = mysql_query($sql);
    while ($forums = mysql_fetch_array($get_forums) ) {
    echo ('<a href="forums.php?forum'.$forums["ID"].'">'.$forums["forums"].'</a><br />');
    }
    }

    else {
    $thread = $_GET['thread'];
    if (!isset ($thread) ) {
    $sql = "SELECT thread, ID FROM forum".$forum;
    $get_threads = mysql_query($sql);
    while ($threads = mysql_fetch_array($get_forums) ) {
    echo ('<a href="forums.php?forum='.$forum.'&thread='.$threads["ID"].'">');
    echo ($threads["thread"].'</a><br />');
    }
    }
    else {
    $sql = "SELECT messages FROM thread".$thread;
    $get_messages = mysql_query($sql);
    while ($messages = mysql_fetch_array($get_messages) ) {
    echo ('<table><tr><td>'.$messages["message"].'</td></tr></table>');
    }
    }
    ?>


    This example uses the same principals and the same overall concept as the first example, including the use of Superglobal arrays and control structures.

    This example is easy to expand, because the main difference between one page and the next is the name of variables, the number of if/else statements, and the number of parts.

    If/else control structures can be substituted with a select case structure if you'd prefer

    Quick Tips
    • When designing a site, always do HTML first, then incorporate PHP
    • Start with multipurpose pages -- don't code and then convert
    • Think of the future and never use commands that have new alternates unless they produce different effects.
    • GET data doesn't have to come from a form, it can be 'placed in' by links instead

    More PHP Articles
    More By Unknown User


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway