sono
09-08-2005, 05:24 PM
hi guys, i have 2 jscript pieces of code. One is not displaying the records together with the radio buttons, The sql statement works fine (i checked it in Access and it works) but it just won't display, can someone check where i went wrong please. There are no errors, it just displays the 'update" button.
---------------------------------------------------------------
Script 1 - No errors in IE, but is only displaying "update button"
---------------------------------------------------------------
<html>
<head>
<title>Attendance Records</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
-->
</style>
</head>
<body>
<%@ LANGUAGE="JAVASCRIPT" %>
<%
var conn;
var rs;
var strSQL;
var fld;
conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE = " + Server.MapPath("db1.mdb"));
if(Request.Form("update") == "update"){
for (var fld in Request.Form)
{
if(Left(fld,7) == "status_"){
student_id = CLng(Mid(fld,8));
attendance = Request.Form(fld);
strSQL = "Update tblattendatt_status = '" + attendance + "' WHERE studentID = " + student_id + " && att_date = Date()";
conn.Execute (strSQL);
if(recsupdated == 0){
conn.Execute = "Insert INTO tblattend(studentID,att_status,att_date) VALUES(" + student_id + ",'" + attendance + "', #" + Month(Date()) + "/" + Day(Date()) + "/" + Year(Date()) + "#)";
}
}
next;
}
rs = conn.Execute("Select tblstudent.studentID, tblstudent.Name, tblattend.att_status From tblstudent LEFT JOIN tblattend ON (tblstudent.studentID = tblattend.studentID && tblattend.att_date = Date()) ORDER by tblstudent.Name");
function currentstatus(statval){
if(rs("att_status") == statval){
currentstatus = " checked";
}else{
currentstatus = "";
}
}
%>;
<div align="center"><strong><font size="3">Attendance records for today</font></strong></div>;
<form name="form1" method="post" action="">;
<table width="50%" border="0" align="center" cellpadding="4" cellspacing="0">;
<tr bgcolor="#CCCCCC">;
<td width="58%"><strong>Student</strong></td>;
<td width="14%"><strong>Present</strong></td>;
<td width="14%"><strong>Absent</strong></td>;
<td width="14%"><strong>Late</strong></td>;
</tr>;
<%
while (!rs.eof) {
Response.Write("<tr>");
Response.Write("<td>" + rs("Name") + "</td>");
Response.Write("<td><input type=radio name='status_" + rs("studentID") + "' value='P" + currentstatus("P") + "'></td>");
Response.Write("<td><input type=radio name='status_" + rs("studentID") + "' value='A" + currentstatus("A") + "'></td>");
Response.Write("<td><input type=radio name='status_" + rs("studentID") + "' value='L" + currentstatus("L") + "'></td>");
Response.Write("</tr>");
rs.movenext();
Wend();
}
rs.Close();
conn = null;
}
%>
<tr bgcolor="#CCCCCC"><td></td><td></td><td></td><td><input type="submit" name="update" value="update"></td></tr>
</table>
</form>
</body>
</html>
------------------------------------------
second script
-------------------------------------------
there's an error with the SQL statement. IE says Syntax error (missing operator) in query expression "'studentID = 2 && att_date > Date() - 30'."
here is the code, i highlighted the problem line in BOLD.
<%@ LANGUAGE="JAVASCRIPT" %>
<%
var student_id, conn, strSQL, rs, TC, SC, percentpresent;
student_id = 2 // this would normally befrom a form value;
ndays = 30 // calculates statistic for the last ndays
conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE = " + Server.MapPath("db1.mdb"));
strSQL = "SELECT Count(*) as TotalCount FROM tblattend Where studentID = " + student_id + " && att_date > Date() - " + ndays + ";";
rs = conn.Execute(strSQL);
TC = rs("TotalCount");
rs.Close;
strSQL = "SELECT Count(tblattend.att_status) as StatusCount, tblstudent.Name " + "FROM tblattend INNER JOIN tblstudent ON (tblattend.studentID = tblstudent.studentID) " + "WHERE tblattend.studentID = " + student_id + " && att_status = 'P' && (att_date > Date() - " + ndays + ") " + "GROUP BY tblstudent.Name"
rs = conn.Execute(strSQL);
if(! rs.EOF){
SC = rs("StatusCount");
if(TC > 0){
percentpresent = ROUND(SC * 100.0 / TC, 0);
}else{
percentpresent = 0;
}
response.write("Presence for " + rs("Name") + " over past " + ndays + " days : " + percentpresent + "%");
}else{
Response.Write("No records found");
}
rs.Close
rs = null;
conn.Close
conn = null;
%>
---------------------------------------------------------------
Script 1 - No errors in IE, but is only displaying "update button"
---------------------------------------------------------------
<html>
<head>
<title>Attendance Records</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
}
-->
</style>
</head>
<body>
<%@ LANGUAGE="JAVASCRIPT" %>
<%
var conn;
var rs;
var strSQL;
var fld;
conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE = " + Server.MapPath("db1.mdb"));
if(Request.Form("update") == "update"){
for (var fld in Request.Form)
{
if(Left(fld,7) == "status_"){
student_id = CLng(Mid(fld,8));
attendance = Request.Form(fld);
strSQL = "Update tblattendatt_status = '" + attendance + "' WHERE studentID = " + student_id + " && att_date = Date()";
conn.Execute (strSQL);
if(recsupdated == 0){
conn.Execute = "Insert INTO tblattend(studentID,att_status,att_date) VALUES(" + student_id + ",'" + attendance + "', #" + Month(Date()) + "/" + Day(Date()) + "/" + Year(Date()) + "#)";
}
}
next;
}
rs = conn.Execute("Select tblstudent.studentID, tblstudent.Name, tblattend.att_status From tblstudent LEFT JOIN tblattend ON (tblstudent.studentID = tblattend.studentID && tblattend.att_date = Date()) ORDER by tblstudent.Name");
function currentstatus(statval){
if(rs("att_status") == statval){
currentstatus = " checked";
}else{
currentstatus = "";
}
}
%>;
<div align="center"><strong><font size="3">Attendance records for today</font></strong></div>;
<form name="form1" method="post" action="">;
<table width="50%" border="0" align="center" cellpadding="4" cellspacing="0">;
<tr bgcolor="#CCCCCC">;
<td width="58%"><strong>Student</strong></td>;
<td width="14%"><strong>Present</strong></td>;
<td width="14%"><strong>Absent</strong></td>;
<td width="14%"><strong>Late</strong></td>;
</tr>;
<%
while (!rs.eof) {
Response.Write("<tr>");
Response.Write("<td>" + rs("Name") + "</td>");
Response.Write("<td><input type=radio name='status_" + rs("studentID") + "' value='P" + currentstatus("P") + "'></td>");
Response.Write("<td><input type=radio name='status_" + rs("studentID") + "' value='A" + currentstatus("A") + "'></td>");
Response.Write("<td><input type=radio name='status_" + rs("studentID") + "' value='L" + currentstatus("L") + "'></td>");
Response.Write("</tr>");
rs.movenext();
Wend();
}
rs.Close();
conn = null;
}
%>
<tr bgcolor="#CCCCCC"><td></td><td></td><td></td><td><input type="submit" name="update" value="update"></td></tr>
</table>
</form>
</body>
</html>
------------------------------------------
second script
-------------------------------------------
there's an error with the SQL statement. IE says Syntax error (missing operator) in query expression "'studentID = 2 && att_date > Date() - 30'."
here is the code, i highlighted the problem line in BOLD.
<%@ LANGUAGE="JAVASCRIPT" %>
<%
var student_id, conn, strSQL, rs, TC, SC, percentpresent;
student_id = 2 // this would normally befrom a form value;
ndays = 30 // calculates statistic for the last ndays
conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE = " + Server.MapPath("db1.mdb"));
strSQL = "SELECT Count(*) as TotalCount FROM tblattend Where studentID = " + student_id + " && att_date > Date() - " + ndays + ";";
rs = conn.Execute(strSQL);
TC = rs("TotalCount");
rs.Close;
strSQL = "SELECT Count(tblattend.att_status) as StatusCount, tblstudent.Name " + "FROM tblattend INNER JOIN tblstudent ON (tblattend.studentID = tblstudent.studentID) " + "WHERE tblattend.studentID = " + student_id + " && att_status = 'P' && (att_date > Date() - " + ndays + ") " + "GROUP BY tblstudent.Name"
rs = conn.Execute(strSQL);
if(! rs.EOF){
SC = rs("StatusCount");
if(TC > 0){
percentpresent = ROUND(SC * 100.0 / TC, 0);
}else{
percentpresent = 0;
}
response.write("Presence for " + rs("Name") + " over past " + ndays + " days : " + percentpresent + "%");
}else{
Response.Write("No records found");
}
rs.Close
rs = null;
conn.Close
conn = null;
%>