MySQL
  Home arrow MySQL arrow Page 7 - The Perfect Job (part 1)
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Forums Sitemap 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
VPS Hosting 
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? 
Google.com  
MYSQL

The Perfect Job (part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2001-06-28


    Table of Contents:
  • The Perfect Job (part 1)
  • An Ideal World
  • Entry Point
  • Going To The Database
  • The Five Rs
  • Lucky Thirteen
  • Building The Foundation
  • The Devil Is In The Details
  • Applying Yourself
  • Testing Times
  • Filing It All Away

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    The Perfect Job (part 1) - Building The Foundation
    (Page 7 of 11 )

    With the database designed and out of the way, it's time to start writing some code to interface with it. The first script, "job_list.php", is the entry point to the application, and simply displays a list of available jobs, classified by department.

    <? // job_list.php - display list of open jobs // includes include("config.php"); include("functions.php"); ?> <html> <head> <basefont face="Verdana" size="2"> </head> <body bgcolor=white> <? $image="listings.jpg"; ?> <? include("header.inc.php"); ?> <? // generate list ?> <? include("footer.inc.php"); ?> </body> </html>
    Each page generated through this application has a particular layout - a blue banner at the top, a logo at the right, and a title (actually an image). The bottom of every page has a copyright notice and a disclaimer. Since these elements will remain constant, through the application, I've placed the corresponding HTML code in separate header and footer files, and simply include()d them on each page.

    Again, by separating common interface elements into separate files, I've made it easier to customize the look of the application; simply alter these files, and the changes will be reflected on all the pages.

    The variable $image stores the name of the image title for each page, and is used by "header.inc.php" - as you can see.

    <!-- appears at the top of every page --> <table bgcolor="6583C3" width="100%" cellspacing="0" cellpadding="0"> <tr> <td height=50 align=right> <img src="images/header.gif" alt="" border="0"></td> </tr> </table> <p> <img src="images/<? echo $image; ?>" alt="" border="0"> <p> <!-- end of header.inc -->
    In addition, two other files, "config.php" and "functions.php" are also included at the top of every page - they store database access information and useful functions, respectively.

    <? // config.php - useful variables // database parameters // alter this as per your configuration $database="jobs"; $user = "root"; $pass = ""; $hostname = "localhost"; ?>
    Back to "job_list.php" - here's the code that takes care of connecting to the database and actually generating the job listing.

    <? include("header.inc.php"); ?> <? // open connection to database $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); // get list of departments with open jobs $query = "SELECT DISTINCT id, department from department, listing WHERE department.id = listing.fk_department"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); // iterate through resultset while(list($id, $department) = mysql_fetch_row($result)) { // print department name echo "<b>Department:</b> $department"; // look for jobs within the department and print as list $query2 = "SELECT jcode, designation from listing WHERE listing.fk_department = '$id'"; $result2 = mysql_db_query($database, $query2, $connection) or die ("Error in query: $query2. " . mysql_error()); echo "<ul>"; while(list($jcode, $dsg) = mysql_fetch_row($result2)) { echo "<li><a href=job_details.php?jcode=$jcode>$dsg ($jcode)</a>"; } echo "</ul>"; echo "<p>"; } // clean up mysql_close($connection); ?> <? include("footer.inc.php"); ?>
    In this case, I've first queried the "listing" table for a list of departments holding open jobs - note the DISTINCT keyword to eliminate duplicate entries. Then, for each of those departments, I've printed the job designation and job code, and linked it to a script which will display further information.

    Here's what it looks like:



    This article copyright Melonfire 2001. All rights reserved.

     
     
    >>> More MySQL Articles          >>> More By icarus, (c) Melonfire
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...



     



    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek