Page Disappears

J

Justice75

HI All,

I am having a problem that is driving me crazy. I have this asp file
which queries three table sin the db and writes the records. That part
is fine (process). The page is sorted in ascending order by a field
inthe db name CYear. The results are crazy. It misses, refuses to pass
or ignores 7 records. By the way which is the equivalentto one page.
The page size is divided into 7 records per page. Also, when is fails
to send the missing records which ARE in the db it doubles some records.
Meaning a record could be on page 1 but it is also showing up on page 3
or a record could be on the bottom of page 4 but it also shows up on the
top of page 5. This thing is KILLING me, please help. The other
aspects of the page work fine. It is just when we added the sortBy
function that it all went crazy. Please help. The page is long but
simple to follow. Any help would be greatly appreciated.

Thanks,

Justice


THE CODE:::

<%@LANGUAGE="JScript" CODEPAGE="1252"%>
<%

//my connection string. you may use yours instead.
var dbPath,dbName,sConn, strCN;

//This is your connection string
var sConn = "dsn=thePartyKidsDB";

//Create Connection
var oConn = Server.CreateObject("ADODB.Connection");
oConn.Open (sConn);

// This is the page number that supplied by the Flash calling this page.
var pageNumber = parseInt(Request.Form("pageNumber"));
//var pageNumber = 2; //comment out

// This is the school that supplied by the Flash calling this page.
var eSName = Request.Form("eSName");


//This is the page size
var pageSize = 7;

//This is your actual query
var tableName = "MemberRegistration INNER JOIN (MemberLogin INNER JOIN
MemberPreferences ON MemberLogin.MRID = MemberPreferences.MRID) ON
(MemberLogin.MRID = MemberRegistration.MRID) AND
(MemberRegistration.MRID = MemberPreferences.MRID)";

//Your field list
var fields = "MemberLogin.MRID, MemberLogin.UName,
MemberRegistration.MRID, \
MemberRegistration.FFName, MemberRegistration.FNName,
MemberRegistration.FLName, \
MemberRegistration.CFName, MemberRegistration.CNName,
MemberRegistration.CLName, \
MemberRegistration.ESName, MemberRegistration.ESYear,
MemberRegistration.MSName, \
MemberRegistration.MSYear, MemberRegistration.HSName,
MemberRegistration.HSYear, \
MemberRegistration.PSName, MemberRegistration.PSYear,
MemberRegistration.CName, \
MemberRegistration.CYear, MemberRegistration.OName,
MemberRegistration.OYear, \
MemberPreferences.MRID, MemberPreferences.BMonth,
MemberPreferences.BDate, \
MemberPreferences.MStatus, MemberPreferences.NKids,
MemberPreferences.Occupation, \
MemberPreferences.City, MemberPreferences.State \
";
//your filter clause
////////////////////////////////////////////////////////////////////////
////////////////
var queryFilter = "(((MemberRegistration.CName)= '" + eSName + "'))"
////////////////////////////////////////////////////////////////////////
////////////////
//Paging query setting
var primaryKey = "MemberRegistration.MRID";
var prevString = pageSize * (pageNumber-1);
//optional sorting (didnt use it)
//========================================================

var sortField = "MemberRegistration.CYear";
var sortDir = "ASC";

//The Paging query

var sSQL = "SELECT (SELECT ((COUNT(*) - 1)/" + pageSize + "+ 1) FROM "
+ tableName + " WHERE " + queryFilter + ") AS PageCount,(SELECT
COUNT(*) FROM " + tableName + " WHERE " + queryFilter + ") AS
totalCount, " + fields + " \
FROM " + tableName + " \
WHERE " + primaryKey + " IN \
( \
SELECT TOP " + pageSize + " " + primaryKey + " \
FROM " + tableName + " \
WHERE " + queryFilter
if (prevString > 0)
{
sSQL += " AND " + primaryKey + " NOT IN \
( \
SELECT TOP " + prevString + "
" + primaryKey + " \
FROM " + tableName + " \
WHERE " + queryFilter ;
if ( sortField )
{
sSQL += " ORDER BY "
+ sortField ;
}
if ( sortField && sortDir )
{
sSQL += " " +
sortDir ;
}
sSQL += " ) " ;
if ( sortField )
{
sSQL += " ORDER BY " + sortField ;
}
if ( sortField && sortDir )
{
sSQL += " " + sortDir ;
}
}
sSQL += " ) ";
if ( sortField )
{
sSQL += " ORDER BY " + sortField ;
}
if ( sortField && sortDir )
{
sSQL += " " + sortDir ;
}

//opening the recordset
var rs = Server.CreateObject("ADODB.Recordset");
with(rs)
{
ActiveConnection = oConn;
CursorType = 3
CursorLocation = 3;
LockType = 1
Source = sSQL;
Open();
}

var strRW = "&";
//Im not sure if you need the counter now. Do you think that I need the
counter? Would it give me the total number of records or just the total
number on the page?
var numCO = 0;
totalcounter= rs.Fields("totalCount").Value;
pagecounter= Math.floor(rs.Fields("PageCount").Value);

//I can suggest you to get rs fields using: rs.Fields("fieldName").Value
while( !rs.EOF)
{
//In JS, the concatenation is done using the +.
strRW += "UName" + numCO + "=" + rs.Fields("UName").Value
+ "&BMonth" + numCO + "=" + rs.Fields("BMonth").Value
+ "&BDate" + numCO + "=" + rs.Fields("BDate").Value
//+ "&BYear" + numCO + "=" + rs.Fields("BYear").Value
+ "&MStatus" + numCO + "=" + rs.Fields("MStatus").Value
+ "&NKids" + numCO + "=" + rs.Fields("NKids").Value
+ "&Occupation" + numCO + "=" +
rs.Fields("Occupation").Value
+ "&City" + numCO + "=" + rs.Fields("City").Value
+ "&State" + numCO + "=" + rs.Fields("State").Value
+ "&FFName" + numCO + "=" + rs.Fields("FFName").Value
+ "&FNName" + numCO + "=" + rs.Fields("FNName").Value
+ "&FLName" + numCO + "=" + rs.Fields("FLName").Value
+ "&CFName" + numCO + "=" + rs.Fields("CFName").Value
+ "&CNName" + numCO + "=" + rs.Fields("CNName").Value
+ "&CLName" + numCO + "=" + rs.Fields("CLName").Value
+ "&ESName" + numCO + "=" + rs.Fields("ESName").Value
+ "&ESYear" + numCO + "=" + rs.Fields("ESYear").Value
+ "&MSName" + numCO + "=" + rs.Fields("MSName").Value
+ "&MSYear" + numCO + "=" + rs.Fields("MSYear").Value
+ "&HSName" + numCO + "=" + rs.Fields("HSName").Value
+ "&HSYear" + numCO + "=" + rs.Fields("HSYear").Value
+ "&PSName" + numCO + "=" + rs.Fields("PSName").Value
+ "&PSYear" + numCO + "=" + rs.Fields("PSYear").Value
+ "&CName" + numCO + "=" + rs.Fields("CName").Value
+ "&CYear" + numCO + "=" + rs.Fields("CYear").Value
+ "&OName" + numCO + "=" + rs.Fields("OName").Value
+ "&OYear" + numCO + "=" + rs.Fields("OYear").Value + "&"
//+ "&Total" + numCO + "=" + rs.Fields("totalCount").Value
// just in case Ive provided that total record count
//+ "&PageCount" + numCO + "=" +
Math.floor(rs.Fields("PageCount").Value) + "&" //the page count that
you need in your Flash
//+ "&Article" + numCO + "=" + rs.Fields("Article").Value +
"&"
;
rs.MoveNext();
numCO++;
}
//screen test can I take the line breaks out
//Response.Write(strRW);

//I don't think that you need the tot now, since it will alwase show the
page size - see line 94?
Response.Write(strRW + "tot=" + numCO + "&"+"tCounter=" + totalcounter +
"&" + "pCounter=" + pagecounter);

rs.close();
rs = null;
oConn.Close();
oConn=null;
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top