One of the three values is contained in the $projectdetails['status'] variable. The only difficulty here is that you need to show the other two values in case the user wants to change from the current status. For example, say the status of the project is 'pending.' The user loads the edit_project page and that is the status that he should see on the form. However, the user must also be able to change that status to any of the other two states (overdue and completed). So, we need to create a select box that will show the current status of the project as well as give the user the option to change the status. The logical steps to take in this case, are to first determine what value is in the $projectdetails['status'] variable, and then use the select box 'selected' attribute to select that value. I've used the switch() structure to do that work for me: <select name="status" id="status"> <?php $list=array('overdue','completed','pending'); switch($projectdetails['status']){
case "overdue": echo "<option value='overdue' selected";
break; case "completed": echo "<option value='completed' selected";
break; case "pending": echo "<option value='pending' selected";
break; } Once I've determined what the value of the variable is and selected it, I then run a for() loop and list all three values in the select box. You will see that I created an array called $list (highlighted in red above) that contains all three values: for($x=0; $x < 4; $x++){ echo ">" .$list[$x]. "</option>"; } ?> </select> <input type="hidden" name="p_pid" value="<?php echo $_GET['pid']?>"/> </label></td> </tr> <tr> <td>Date Due </td> <td><label> <? $dd = date("d"); $mm = date("m"); $yy = date("Y"); echo "<select name="dd">n"; for($i = 1; $i <= 31; $i++) { echo "<option value="" . $i . """; if($i == $dd) { echo " selected"; } echo ">" . $i . "</option>n"; } echo "</select> <select name="mm">n"; for($i = 1; $i <= 12; $i++) { echo "<option value="" . $i . """; if($i == $mm) { echo " selected"; } echo ">" . $month_names[$i] . "</option>n"; } echo "</select> <select name="yy">n"; for($i = $yy; $i <= ($yy + 1); $i++) { echo "<option value="" . $i . """; if($i == $yy) { echo " selected"; } echo ">" . $i . "</option>n"; } echo "</select>"; ?> <input type="hidden" name="createdt" value="<?php echo $projectdetails['create_dt']?>" /> </label></td> </tr> <tr> <td> </td> <td><label> <input name="submit" type="submit" id="submit" value="Update!" /> </label></td> </tr> </table> </form> <!-- InstanceEndEditable --></td> </tr> <tr> <td colspan="3"><!-- InstanceBeginEditable name="nav" --><table width="100%" border="0"> <tr> <td><a href="edit_task.php?pid=<?php echo $projectdetails['pid'];?>">Change a Task in this Project</a> | <a href="edit_staff.php?pid=<?php echo $projectdetails['pid'];?>">Change Staff members of this Project </a> | <a href="main.php">View Project List</a> | <a href="admin/login.php">Administrators Corner </a> </td> </tr> </table><!-- InstanceEndEditable --></td> </tr> <tr> <td align="right" class="cright" colspan="3">copyright © 2007 PM </td> </tr> </table> </body> <!-- InstanceEnd --></html> That's all there is to the edit project script. The next article will look at adding, editing, and viewing tasks for a particular project.
blog comments powered by Disqus |
|
|
|
|
|
|
|