In the HTML below, the $num variable is going to be used to create a dynamic table. This table will list all the staff working on this project. It will also give the user the option to remove staff from the project. This will be done dynamically based on the number of rows returned by the query we ran above: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/PM_Main.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <!-- InstanceBeginEditable name="head" --> <!-- InstanceEndEditable --> <link href="Templates/main.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="100%" border="0"> <tr> <td width="33%"> </td> <td width="28%"> </td> <td width="39%">Logged in: <!-- InstanceBeginEditable name="login" --><? echo $_SESSION['name'];?> | <a href="logout.php">Logout</a><!-- InstanceEndEditable --></td> </tr> <tr> <td colspan="3" bgcolor="#6699CC" class="headertxt">Project Management Software </td> </tr> <tr> <td colspan="3"><!-- InstanceBeginEditable name="main" --> <table width="99%" border="0"> <tr> <td colspan="2" class="loginheader"><?php echo $title;?> </td> </tr> <tr> <td width="44%">Members of this project: </td> <td width="56%"> </td> </tr> <tr> <td> </td> <td> </td> </tr> The static headers for the table are created here. The action header will host the option for the user to delete a staff member from the project: <tr> <td><strong> Name</strong></td> <td><strong>Action</strong></td> </tr> The dynamic rows are created here, with the use of the $num variable. Depending on the value contained in the $num variable, the dynamic rows will be built. At the same time PHP is going to retrieve the results of the query through a results array called $row and populate the dynamic rows with it. Also, a hyper link is built linking the Delete action with the delete_member.php script: <?php if($num > 0){ while($row = mysql_fetch_assoc($result)){?> <tr> <td><?php echo $row['name']?> </td> <td><a href="delete_member.php?sid=<?php echo $row['sid']?> & cpid=<?php echo $cpid?> ">Delete</a></td> </tr> If the $num variable does not have a value that is greater than zero, it means that the query did not return any results: <?php } }else{ ?> <tr> <td colspan="2"><p>There are no members registered for this project.</p></td> </tr> <?php } ?> </table><!-- InstanceEndEditable --></td> </tr> <tr> <td colspan="3"><!-- InstanceBeginEditable name="nav" --><a href="main.php">View Project List</a> | <a href="admin/login.php">Administrators Corner </a><!-- InstanceEndEditable --></td> </tr> <tr> <td align="right" class="cright" colspan="3">copyright © 2007 PM </td> </tr> </table> </body> <!-- InstanceEnd --></html> Finally we look at thedelete_member.phpscript that deletes staff members from the project: <?php include "dbcon.php"; include "functions.php"; $csid = mysql_escape_string($_GET['sid']); $remove = "DELETE FROM staff WHERE sid = '".$csid."'"; mysql_query($remove); header("localtion:view_staff.php?pid=".$_GET['cpid'].""); ?> The code is straightforward; it basically removes the name of the staff member from the staff table, based on the staff id that it receives from the view staff script. And that concludes our series. We've come a long way in seven articles. I hope you've enjoyed the trip.
blog comments powered by Disqus |
|
|
|
|
|
|
|