Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: A logic error?????


Message #1 by "Linday Bakharia" <lindsay_bakharia@h...> on Wed, 20 Feb 2002 01:29:32
Hi,



I called it a logic error because it gives me no error when I run it.



What makes me unhappy is that when I added the code for "Paging through 

database results N records at a time", it didn't do what it should be 

doing.  For instance, if I display all the records on 1 page, it works 

just fine. All the users' answers will be stored in the db. But if I 

display the records more than 1 page, then the users' answers won't be 

captured in the db.  After I fill out the survey form and click Submit 

button, it does take me to the thank you page and pretends as if 

everything is working fine.  But when I go back to the db and check, only 

the values from the first page are stored, the rest (values on the second, 

third pages) is nowhere to be found.  Where did they go????



Any help is very appreciated.  :)



*******************

<%



'Set how many records per page we want

Const NumPerPage = 3



'Retrieve what page we're currently on

Dim CurPage

    If Request.QueryString("CurPage") = "" then

        CurPage = 1 'We're on the first page

    Else

        CurPage = Request.QueryString("CurPage")

    End If



Set Conn = Server.CreateObject("ADODB.Connection")

Set Rs = Server.CreateObject("ADODB.Recordset")







'Set the cursor location property

rs.CursorLocation = adUseClient



'Set the cache size = to the # of records/page

rs.CacheSize = NumPerPage

Conn.Open dsn

    

SQL = "SELECT * from que order by id desc"

rs.open sql,conn



rs.MoveFirst

rs.PageSize = NumPerPage





'Get the max number of pages

Dim TotalPages

TotalPages = rs.PageCount



'Set the absolute page

rs.AbsolutePage = CurPage



'Counting variable for our recordset

Dim count



'Set Count equal to zero

Count = 0

Do While Not rs.EOF And Count < rs.PageSize

	  

    queID = rs("ID")

    sql1 = "select * from ans where queID="&queID

    response.write "<b>" & rs("que") & "</b><br>"

    response.write "<input type='hidden' name='queID' value="&queID&">"

    set rs1=conn.execute(sql1)

	

    do while not rs1.eof

	response.write "<input type=radio name=poll"&queID & " value='"&rs1

("id")&"'>"&rs1("ansdesc") & "<br>"

	 

	rs1.movenext

    loop

    Count = Count + 1

    rs.MoveNext

Loop



    'Print out the current page # / total pages

    Response.Write("Page " & CurPage & " of " & TotalPages & "<P>")



    'Display Next / Prev buttons

    if CurPage > 1 then

        'We are not at the beginning, show the prev button

        Response.Write("<INPUT TYPE=BUTTON VALUE=PREV 

ONCLICK=""document.location.href='index.asp?curpage=" & curpage - 1 

& "';"">")

    End If



if CInt(CurPage) <> CInt(TotalPages) then

        'We are not at the end, show a next button

        Response.Write("<INPUT TYPE=BUTTON VALUE=NEXT 

ONCLICK=""document.location.href='index.asp?curpage=" & curpage + 1 

& "';"">")

    End If



%>





<input type=submit name="submit" value="vote"><input type=button 

name="res" value="Results" onclick="location.href='poll.asp?

action=view'"><br><br>

*************************

  Return to Index