Forums
This topic is locked
Can I do this?
Posted 29 Jul 2005 03:57:03
1
has voted
29 Jul 2005 03:57:03 Linda Farruggia posted:
Situation: Have an asp search page (note we are a public school). Have students tied to classes. Search page brings up class names and id in results click on ID - Results links to a page that lists all students in that class. Works great - now I need to take that list and tie it to an insert into attendance table. Can I have a dynamic page that returns student name, id, class name, and then inserts into a table for attendance? (Data base is sql)I then want to be able to have (insert fields next to those names like attendance code and auto date.
Click on insert and voila it takes the list and inserts it into the attendance table!
I have tried several things and everytime I try to enter an insert form along in the results page - bingo error error? I have thought about session variables, but I really need to bring up a class list and just have users enter attendance code. I'm trying to keep it simple for teachers without having to go to several pages or worse yet bring up each student at a time.
Any help would be so greatly appreciated. It's probably something I should be writing in sql ??? Any suggestions in that area? I'm not real great yet with sql, but I have tried tieing tables in view, but that isn't help either.
Replies
Replied 02 Aug 2005 01:31:05
02 Aug 2005 01:31:05 Raafat Abdul replied:
It looks like you need to do a multiple insert and for that, you will need to write the code because Dreamweaver will not do it for you.
Now, in the page which returns all the students in a particular class:
1- Add hidden fields next to each field being returned by the record set and give each hidden field a name and the value of the record field.
2- Add a text box at the end of the dynamic table and call it "ATTENDANCE". This is the box where you will be writing the attendance mark next to each student. Assuming when you run the result page and it returned 5 student records, you will have 5 empty text boxes next to each student respectively.
3- Add a hidden field to store the number of records you have on the result page and you can use a small JavaScript to store that number. The number returned is used when doing the insertion loop.
4- Look at the code marked "The insertion code" in the page "students.asp"
In my example, I created 2 tables. A STUDENT table and ATTENDANCE table.
The STUDENTS table contains the fields:
ID as Number
NAME as string
CLASSNAME as string
The ATTENDANCE table contains the fields:
ID as Number
NAME as string
CLASSNAME as string
ATTENDANCE as string
DATE as system date
<b> Students Page "students.asp" </b>
<pre id=code><font face=courier size=2 id=code>
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/DBConnection.asp" -->
<%
var rsSTUDENTS = Server.CreateObject("ADODB.Recordset"
rsSTUDENTS.ActiveConnection = MM_DBConnection_STRING;
rsSTUDENTS.Source = "SELECT ID, NAME, CLASSNAME FROM STUDENTS ORDER BY ID";
rsSTUDENTS.CursorType = 0;
rsSTUDENTS.CursorLocation = 2;
rsSTUDENTS.LockType = 1;
rsSTUDENTS.Open();
var rsSTUDENTS_numRows = 0;
%>
<%
var Repeat1__numRows = -1;
var Repeat1__index = 0;
rsSTUDENTS_numRows += Repeat1__numRows;
%>
<%
// The insertion code
if (String(Request("MM_insert") == "form1"
{
var i;
var totalStudents=Request.Form("totalStudents" // How namy students we have on the page
for(i=0;i<totalStudents;i++)
{
// We have to split the ID because if we have 5 students for example, we will
// get the IDs as 1,2,3,4,5 and the separator is the comma.
intID = "" + Request("ID" + ""
myID=intID.split(","
// We do the same for the STUDENT NAMES as we did for the ID
charNAME = "" + Request("NAME" + ""
myNAME=charNAME.split(","
// We do the same for the CLASS NAMES as we did for the ID
charCLASSNAME = "" + Request("CLASSNAME" + ""
myCLASSNAME=charCLASSNAME.split(","
// We do the same for the ATTENDANCE as we did for the ID
charATTENDANCE = "" + Request("ATTENDANCE" + ""
myATTENDANCE=charATTENDANCE.split(","
// Do the insert
var Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_DBConnection_STRING;
Command1.CommandText = "INSERT INTO ATTENDANCE (ID, NAME,CLASSNAME,ATTENDANCE,TIMESTAMP) VALUES (" + myID[i] + ",'" + myNAME[i] +"','" + myCLASSNAME[i] +"','" + myATTENDANCE[i] +"' , SYSDATE)";
Command1.CommandType = 1;
Command1.CommandTimeout = 0;
Command1.Prepared = true;
Command1.Execute();
}
// Once the loop is over, we direct to the attendance page
var MM_editRedirectUrl = "attendance.asp";
if (MM_editRedirectUrl) {Response.Redirect(MM_editRedirectUrl);}
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="">
<table border="1">
<tr bgcolor="#CCCCCC">
<td><div align="center">Student ID</div></td>
<td><div align="center">Student Name </div></td>
<td><div align="center">Class Name </div></td>
<td><div align="center">Attendance</div></td>
</tr>
<% while ((Repeat1__numRows-- != 0) && (!rsSTUDENTS.EOF)) { %>
<tr>
<td><%=(rsSTUDENTS.Fields.Item("ID".Value)%>
<input name="ID" type="hidden" id="ID" value="<%=(rsSTUDENTS.Fields.Item("ID".Value)%>"> </td>
<td><%=(rsSTUDENTS.Fields.Item("NAME".Value)%>
<input name="NAME" type="hidden" id="NAME" value="<%=(rsSTUDENTS.Fields.Item("NAME".Value)%>"></td>
<td><%=(rsSTUDENTS.Fields.Item("CLASSNAME".Value)%>
<input name="CLASSNAME" type="hidden" id="CLASSNAME" value="<%=(rsSTUDENTS.Fields.Item("CLASSNAME".Value)%>"></td>
<td><input name="ATTENDANCE" type="text" id="ATTENDANCE"></td>
</tr>
<%
Repeat1__index++;
rsSTUDENTS.MoveNext();
}
%>
</table>
<p><input type="hidden" name="totalStudents" value="form1">
<!-- A small script to tell us how many rows we have in the result table because our
insertion loop depends on that number. -->
<SCRIPT LANGUAGE="JavaScript1.2">document.form1.totalStudents.value=document.form1.ATTENDANCE.length</script>
<input type="hidden" name="MM_insert" value="form1">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<br>
</body>
</html>
<%
rsSTUDENTS.Close();
%>
</font id=code></pre id=code>
<b> Attendance Page "attendance.asp" </b>
<pre id=code><font face=courier size=2 id=code>
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/DBConnection.asp" -->
<%
var rsAttendance = Server.CreateObject("ADODB.Recordset"
rsAttendance.ActiveConnection = MM_DBConnection_STRING;
rsAttendance.Source = "SELECT ID, NAME, CLASSNAME, ATTENDANCE,TIMESTAMP FROM ATTENDANCE ORDER BY ID";
rsAttendance.CursorType = 0;
rsAttendance.CursorLocation = 2;
rsAttendance.LockType = 1;
rsAttendance.Open();
var rsAttendance_numRows = 0;
%>
<%
var Repeat1__numRows = -1;
var Repeat1__index = 0;
rsAttendance_numRows += Repeat1__numRows;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<table border="1">
<tr>
<td><div align="center">ID</div></td>
<td><div align="center">NAME</div></td>
<td><div align="center">CLASSNAME</div></td>
<td><div align="center">ATTENDANCE</div></td>
<td><div align="center">DATE</div></td>
</tr>
<% while ((Repeat1__numRows-- != 0) && (!rsAttendance.EOF)) { %>
<tr>
<td><%=(rsAttendance.Fields.Item("ID".Value)%></td>
<td><%=(rsAttendance.Fields.Item("NAME".Value)%></td>
<td><%=(rsAttendance.Fields.Item("CLASSNAME".Value)%></td>
<td><%=(rsAttendance.Fields.Item("ATTENDANCE".Value)%></td>
<td><%=(rsAttendance.Fields.Item("TIMESTAMP".Value)%></td>
</tr>
<%
Repeat1__index++;
rsAttendance.MoveNext();
}
%>
</table>
<p><a href="students.asp">Add More</a> </p>
</body>
</html>
<%
rsAttendance.Close();
%>
</font id=code></pre id=code>
I hope that will help.
Now, in the page which returns all the students in a particular class:
1- Add hidden fields next to each field being returned by the record set and give each hidden field a name and the value of the record field.
2- Add a text box at the end of the dynamic table and call it "ATTENDANCE". This is the box where you will be writing the attendance mark next to each student. Assuming when you run the result page and it returned 5 student records, you will have 5 empty text boxes next to each student respectively.
3- Add a hidden field to store the number of records you have on the result page and you can use a small JavaScript to store that number. The number returned is used when doing the insertion loop.
4- Look at the code marked "The insertion code" in the page "students.asp"
In my example, I created 2 tables. A STUDENT table and ATTENDANCE table.
The STUDENTS table contains the fields:
ID as Number
NAME as string
CLASSNAME as string
The ATTENDANCE table contains the fields:
ID as Number
NAME as string
CLASSNAME as string
ATTENDANCE as string
DATE as system date
<b> Students Page "students.asp" </b>
<pre id=code><font face=courier size=2 id=code>
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/DBConnection.asp" -->
<%
var rsSTUDENTS = Server.CreateObject("ADODB.Recordset"
rsSTUDENTS.ActiveConnection = MM_DBConnection_STRING;
rsSTUDENTS.Source = "SELECT ID, NAME, CLASSNAME FROM STUDENTS ORDER BY ID";
rsSTUDENTS.CursorType = 0;
rsSTUDENTS.CursorLocation = 2;
rsSTUDENTS.LockType = 1;
rsSTUDENTS.Open();
var rsSTUDENTS_numRows = 0;
%>
<%
var Repeat1__numRows = -1;
var Repeat1__index = 0;
rsSTUDENTS_numRows += Repeat1__numRows;
%>
<%
// The insertion code
if (String(Request("MM_insert") == "form1"
{
var i;
var totalStudents=Request.Form("totalStudents" // How namy students we have on the page
for(i=0;i<totalStudents;i++)
{
// We have to split the ID because if we have 5 students for example, we will
// get the IDs as 1,2,3,4,5 and the separator is the comma.
intID = "" + Request("ID" + ""
myID=intID.split(","
// We do the same for the STUDENT NAMES as we did for the ID
charNAME = "" + Request("NAME" + ""
myNAME=charNAME.split(","
// We do the same for the CLASS NAMES as we did for the ID
charCLASSNAME = "" + Request("CLASSNAME" + ""
myCLASSNAME=charCLASSNAME.split(","
// We do the same for the ATTENDANCE as we did for the ID
charATTENDANCE = "" + Request("ATTENDANCE" + ""
myATTENDANCE=charATTENDANCE.split(","
// Do the insert
var Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_DBConnection_STRING;
Command1.CommandText = "INSERT INTO ATTENDANCE (ID, NAME,CLASSNAME,ATTENDANCE,TIMESTAMP) VALUES (" + myID[i] + ",'" + myNAME[i] +"','" + myCLASSNAME[i] +"','" + myATTENDANCE[i] +"' , SYSDATE)";
Command1.CommandType = 1;
Command1.CommandTimeout = 0;
Command1.Prepared = true;
Command1.Execute();
}
// Once the loop is over, we direct to the attendance page
var MM_editRedirectUrl = "attendance.asp";
if (MM_editRedirectUrl) {Response.Redirect(MM_editRedirectUrl);}
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="">
<table border="1">
<tr bgcolor="#CCCCCC">
<td><div align="center">Student ID</div></td>
<td><div align="center">Student Name </div></td>
<td><div align="center">Class Name </div></td>
<td><div align="center">Attendance</div></td>
</tr>
<% while ((Repeat1__numRows-- != 0) && (!rsSTUDENTS.EOF)) { %>
<tr>
<td><%=(rsSTUDENTS.Fields.Item("ID".Value)%>
<input name="ID" type="hidden" id="ID" value="<%=(rsSTUDENTS.Fields.Item("ID".Value)%>"> </td>
<td><%=(rsSTUDENTS.Fields.Item("NAME".Value)%>
<input name="NAME" type="hidden" id="NAME" value="<%=(rsSTUDENTS.Fields.Item("NAME".Value)%>"></td>
<td><%=(rsSTUDENTS.Fields.Item("CLASSNAME".Value)%>
<input name="CLASSNAME" type="hidden" id="CLASSNAME" value="<%=(rsSTUDENTS.Fields.Item("CLASSNAME".Value)%>"></td>
<td><input name="ATTENDANCE" type="text" id="ATTENDANCE"></td>
</tr>
<%
Repeat1__index++;
rsSTUDENTS.MoveNext();
}
%>
</table>
<p><input type="hidden" name="totalStudents" value="form1">
<!-- A small script to tell us how many rows we have in the result table because our
insertion loop depends on that number. -->
<SCRIPT LANGUAGE="JavaScript1.2">document.form1.totalStudents.value=document.form1.ATTENDANCE.length</script>
<input type="hidden" name="MM_insert" value="form1">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<br>
</body>
</html>
<%
rsSTUDENTS.Close();
%>
</font id=code></pre id=code>
<b> Attendance Page "attendance.asp" </b>
<pre id=code><font face=courier size=2 id=code>
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/DBConnection.asp" -->
<%
var rsAttendance = Server.CreateObject("ADODB.Recordset"
rsAttendance.ActiveConnection = MM_DBConnection_STRING;
rsAttendance.Source = "SELECT ID, NAME, CLASSNAME, ATTENDANCE,TIMESTAMP FROM ATTENDANCE ORDER BY ID";
rsAttendance.CursorType = 0;
rsAttendance.CursorLocation = 2;
rsAttendance.LockType = 1;
rsAttendance.Open();
var rsAttendance_numRows = 0;
%>
<%
var Repeat1__numRows = -1;
var Repeat1__index = 0;
rsAttendance_numRows += Repeat1__numRows;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<table border="1">
<tr>
<td><div align="center">ID</div></td>
<td><div align="center">NAME</div></td>
<td><div align="center">CLASSNAME</div></td>
<td><div align="center">ATTENDANCE</div></td>
<td><div align="center">DATE</div></td>
</tr>
<% while ((Repeat1__numRows-- != 0) && (!rsAttendance.EOF)) { %>
<tr>
<td><%=(rsAttendance.Fields.Item("ID".Value)%></td>
<td><%=(rsAttendance.Fields.Item("NAME".Value)%></td>
<td><%=(rsAttendance.Fields.Item("CLASSNAME".Value)%></td>
<td><%=(rsAttendance.Fields.Item("ATTENDANCE".Value)%></td>
<td><%=(rsAttendance.Fields.Item("TIMESTAMP".Value)%></td>
</tr>
<%
Repeat1__index++;
rsAttendance.MoveNext();
}
%>
</table>
<p><a href="students.asp">Add More</a> </p>
</body>
</html>
<%
rsAttendance.Close();
%>
</font id=code></pre id=code>
I hope that will help.