Home arrow PHP arrow Page 4 - HTML for a Project Management Application

PHP explained - PHP

In this article we will continue discussing the HTML portion of the main.php page and then move on to the page that enables you to view a project in detail. This is the second part of a seven-part article that covers the creation of a project management application.

TABLE OF CONTENTS:
  1. HTML for a Project Management Application
  2. Code Explained
  3. Source Code for the Page
  4. PHP explained
By: David Web
Rating: starstarstarstarstar / 5
June 09, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The PHP code of the page is very straightforward. The main page of the application sends over the project ID when the hyperlink with the project title is clicked. The view_ project page receives this ID, and then retrieves the project details based on the ID number. If you go back and look at the way our database tables are set up, you will notice that each table, with the exception of the users table, has a project ID field. The view_project page uses the same ID to retrieve project information from the following tables:


projects, staff, tasks and files


Once the information is gathered, it is organized and displayed on this page, as you can see from the earlier screen shot. The PHP code starts by including the usual bunch of files and then initializes variables:


<?php

include "dbcon.php";

include "functions.php";

//initialise variables

$alert =false;


Next, it checks whether a project id (pid) is sent over:


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



If so, we start to filter the value. Although this value did not come from a form, we still need to check and verify it, since anyone can modify it while it is displayed in the browser. Because we know that the project ID is a number, it is easy to check it by using the is_numeric() function:


//clean pid

if(!is_numeric($_GET['pid'])){

//the value received is not numeric. redirect the user to login

header("location:login.php");

}



If it is indeed a number, then we need to escape it, before it is used in a MySQL query:


//otherwise clean the received value for query use

//get projects

$projectID = mysql_escape_string($_GET['pid']);


Once the variable has been escaped, we can retrieve the project details from the project table:


$getproject= "SELECT * FROM projects WHERE pid = '".$projectID."'";

$results = mysql_query($getproject);

$projectdetails = mysql_fetch_assoc($results);



Then we retrieve all the files that are connected to the project ID from the files table:


//get project files

$getfiles = "SELECT * FROM files WHERE p_id = '".$projectID."'";

$file_res = mysql_query($getfiles);

if(!$file_res){

echo mysql_error();

}else{

$num_files = mysql_num_rows($file_res);

}

 

And finally, we retrieve all the staff members that work on this project from the staff table:



//get project members

$getmembers = "SELECT name FROM staff WHERE p_id = '".$projectID."'";

$staff_res = mysql_query($getmembers);

if(!$staff_res){

echo mysql_error();

}else{

$num_staff = mysql_num_rows($staff_res);

}

}



The HTML part of the page basically displays the information that is gathered by these queries in an HTML table. If any of the queries return empty, then the appropriate message is displayed.

Conclusion

In the next article we will look at how to add new projects and how to change the contents of a project.



 
 
>>> More PHP Articles          >>> More By David Web
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: