multiple problems in creating an application

This is a discussion on multiple problems in creating an application within the PHP Language forums, part of the PHP Programming Forums category; 1. When I select an assignment, the class roster disappears. I don't want it to show up until I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-17-2005
LS
 
Posts: n/a
Default multiple problems in creating an application

1. When I select an assignment, the class roster disappears. I don't want it to show up until I select an assignment.

2. I want to be able to enter grades and submit all with only one submit button.

This is my code. File is loaded at http://lynnesmith.net/teacher/entergrades.php
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++
<HTML>
<HEAD>
<TITLE>Gradebook</TITLE>
<LINK REL="STYLESHEET" TYPE="text/css" HREF="../stylesheets/gradebook.css">
</HEAD>

<BODY>
<?PHP
include("connect.php");
$CONNECTION = mysql_connect($DB_SERVER, $DB_USER, $DB_PASS) or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db($DB_NAME) or die("Couldn't select database.");
?>
<DIV ID="header">
Enter Grades
</DIV>
<DIV ID="instructions">
<FORM ACTION="entergrades.php" METHOD="post">
<SELECT NAME='classid' SIZE='1'>
<OPTION VALUE='0' SELECTED>--- Select Class ---</OPTION>
<?PHP
$SQL = "SELECT * FROM $DB_TABLE ORDER BY classname";
$RESULT = mysql_query($SQL, $CONNECTION) OR die ('Query failed: ' .
mysql_error());
while ($ROW = mysql_fetch_array($RESULT))
{
$CLASSID = $ROW["classid"];
$CNAME = $ROW["classname"];
echo "<OPTION VALUE='$CLASSID'>$CNAME</OPTION>";
}
?>
</SELECT>
<INPUT TYPE='submit' NAME='checkclass' VALUE="Submit">
</FORM>

<?PHP
if(isset($_POST['checkclass']))
{
$CID = $_POST['classid'];

echo "<FORM ACTION='entergrades.php' METHOD='post'>";
echo "<SELECT NAME='assignid' SIZE='1'>";
echo "<OPTION VALUE='0' SELECTED>--- Select Assignment ---</OPTION>";

$SQL = "SELECT * FROM $DB_TABLE1 WHERE classid = '$CID' ORDER BY name";
$RESULT = mysql_query($SQL, $CONNECTION) OR die ('Query failed: ' .
mysql_error());
$NUM = mysql_num_rows($RESULT);
if ($NUM > 0)
{
while ($ROW = mysql_fetch_array($RESULT))
{
$AID = $ROW["record"];
$ANAME = $ROW["name"];
$VALUE = $ROW["value"];
echo "<OPTION VALUE='$AID'>$ANAME ($VALUE)</OPTION>";
}}
echo "</SELECT>";
echo"<INPUT TYPE='submit' NAME='checkassign' VALUE='Submit'>";
echo "</FORM>";
}

if (isset($_POST['checkassign']))
{
$AID = $_POST['assignid'];
}
?>
</DIV>
<DIV ID="content">

<?PHP
$SQL2 = "SELECT * FROM $DB_TABLE2 WHERE classid = '$CID' ORDER BY
lastname, firstname";
$RESULT2 = mysql_query($SQL2, $CONNECTION) OR die ("Query failed.");
$NUM2 = mysql_num_rows($RESULT2);
if ($NUM2 > 0)
{
echo "<TABLE CELLSPACING='2' CELLPADDING='2' BORDER='1'>";
echo "<TR><TH COLSPAN='4'>$CNAME</TH></TR>";
echo "<TR><TH>ID#</TH><TH>Student</TH><TH>Grade</TH><TH></TH></TR>";
echo "<FORM ACTION='entergrades.php' METHOD='post'>";
while ($ROW = mysql_fetch_array($RESULT2))
{
$SRECORD = $ROW["record"];
$SID = $ROW["studentid"];
$FNAME = $ROW["firstname"];
$LNAME = $ROW["lastname"];
echo "<TR><TD>$SID</TD><TD>$LNAME, $FNAME</TD><TD><INPUT TYPE=text
NAME='grade' SIZE='3' MAXLENGTH='3'></TD></TR>";
}
echo "</FORM>";
echo "<TR><TD COLSPAN='4' ><INPUT TYPE='submit' NAME='grades' VALUE='Add
Grade'></TD> </TR>";
echo "</TABLE>";
}
?>
<?PHP
if(isset($_POST['grades']))
{
$ANUM = $_POST['anum'];
$GRADE = $_POST['grade'];
$SQL3 = "INSERT INTO $DB_TABLE3 (classid, studentid, assignmentid,
grade) VALUES ('$CID', '$SID', '$AID', '$GRADE')";
}
?>
</DIV>
</BODY>
</HTML>
Reply With Quote
  #2 (permalink)  
Old 06-17-2005
kicken
 
Posts: n/a
Default Re: multiple problems in creating an application

LS wrote:
> 1. When I select an assignment, the class roster disappears. I don't
> want it to show up until I select an assignment.
>
> 2. I want to be able to enter grades and submit all with only one submit
> button.

[snip]

Just by looking at the live example, I think the problem to your first
question is that you do not setup the class select box after you choose
a class. It goes back to the default value of --- Select Class ---, so
when you select an assignment and submit, your script does not see a
selected class and displays the orginal page again. So when you create
your class drop down, you need to have a check for if a class has been
choosen, auto-select it on when it's time to choose an assignment.

Same would go for assignment. You'll need to make it automatically
selected once it has been choosen.

For your second question, you'll want to name the grade boxes as an
array. And you might use the student id as the index, just to make
things easier in the script.

<input type="text" name="grade[$SID]">

<?php

foreach ($_POST['grade'] as $sid=>$grade){
//Update database, set grade for student $sid to $grade
}

?>
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0