Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

[ASP and MySQL] Paging

Question posted by: viki1967 (Familiar Sight) on March 25th, 2008 11:29 AM
Hi everyone.

I have problem whit paging ASP and MySQL.

This code not working :

PageSize = 10
Number of records = 1
PageCount = 1/10 = 1

Code: ( text )
  1. Function excess(argValue)
  2.     if not (int(argValue) = argValue) then argValue = int(argValue)+1      
  3.     excess = argValue
  4. end Function
  5.  
  6. pageSize = 10
  7.  
  8. if(len(Request.QueryString("pagina"))=0)then
  9.   currentPage = 1
  10. else
  11.   currentPage = CInt(Request.QueryString("pagina"))
  12. end if
  13.  
  14. sql_count = " SELECT * "
  15. sql_count = sql_count & " , COUNT(*) AS CNT "
  16. sql_count = sql_count & " , COUNT(TIPO) AS totale_tipo "
  17. sql_count = sql_count & " FROM "
  18. sql_count = sql_count & " tbl "
  19.  
  20. sql_count = sql_count & " GROUP BY "
  21. sql_count = sql_count & " TIPO, DATA "
  22. sql_count = sql_count & " ORDER BY "
  23. sql_count = sql_count & " DATA ASC "
  24. sql_count = sql_count & " LIMIT " & (currentPage - 1) * pageSize & ", " & pageSize
  25.  
  26. Set RS = Server.CreateObject("ADODB.Recordset")
  27. RS.Open sql_count, cn
  28.  
  29. If Not RS.eof Then
  30.  
  31.    recordCount = RS("CNT")
  32.    pageCount = excess(clng(recordCount) / clng(pageSize))
  33.  
  34.    for i = 1 to pageCount
  35.      Response.Write("<a href=""pag.asp?pagina=" & i & """>" & i & "</a> ")
  36.    next
  37.  
  38. end if
  39.  
  40. RS.Close
  41. Set RS = Nothing
  42.  
  43. cn.Close
  44. Set cn = Nothing


Was going on ?

Can you help me?
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
viki1967's Avatar
viki1967
Familiar Sight
164 Posts
March 25th, 2008
08:12 PM
#2

Re: [ASP and MySQL] Paging
This code work:

Code: ( text )
  1. <!-- INIZIO PARTE DI CODICE ASP -->
  2.  
  3. <%
  4.  
  5. Session.LCID = 1040
  6. response.expires = -1500
  7. response.AddHeader "PRAGMA", "NO-CACHE"
  8. response.CacheControl = "PRIVATE"
  9.  
  10. 'STRINGA DI CONNESSIONE AL DB MYSQL
  11. sDatabaseConnection = "DRIVER={MySQL ODBC 3.51 Driver};"_
  12.     & "SERVER=localhost;"_
  13.     & "DATABASE=test;"_
  14.                 & "UID=root;PWD=test; OPTION=35;"
  15.  
  16. 'CREO LA CONNESSIONE AL DB MYSQL                   
  17. Set connCount = Server.Createobject("ADODB.Connection")
  18.  
  19. 'APRO LA CONNESSIONE AL DB MYSQL
  20. connCount.open sDatabaseConnection   
  21.  
  22. Function excess(argValue)
  23.     if not (int(argValue) = argValue) then argValue = int(argValue)+1      
  24.     excess = argValue
  25. end Function
  26.  
  27. pageSize = 5
  28.  
  29. if(len(Request.QueryString("pagina"))=0)then
  30.   currentPage = 1
  31. else
  32.   currentPage = CInt(Request.QueryString("pagina"))
  33. end if
  34.  
  35. q1 = "SELECT COUNT(*) FROM tbl "
  36. q2 = "SELECT * FROM tbl ORDER BY DATA ASC LIMIT " & (currentPage - 1) * pageSize & ", " & pageSize
  37.  
  38. recordCount = connCount.Execute(q1).Fields(0)
  39.  
  40. Set RS = Server.CreateObject("ADODB.Recordset")
  41. RS.Open q2, connCount
  42.  
  43. If Not RS.eof Then
  44. Do while not RS.eof
  45.  
  46. response.write RS("Nome") &" - "& RS("data") &" - "& RS("stato") &"<br><br>"
  47.  
  48. RS.movenext()
  49.              Loop
  50.  
  51.    pageCount = excess(clng(recordCount) / clng(pageSize))
  52.  
  53.    for i = 1 to pageCount
  54.      Response.Write("<a href=""paging.asp?pagina=" & i & """>" & i & "</a> ")
  55.    next
  56.  
  57. end if
  58.  
  59. RS.close
  60. set RS = nothing
  61.  
  62. connCount.close
  63. set connCount = nothing
  64.  
  65. %>


I have:

Quote:
Originally Posted by
pippo - 11/03/2008 - in sede
caio - 11/03/2008 - operatore

pippo - 12/03/2008 - operatore
caio - 12/03/2008 - ferie

pippo - 13/03/2008 - ferie
caio - 13/03/2008 - ferie

sempronio - 14/03/2008 - permesso
caio - 14/03/2008 - in sede
pippo - 14/03/2008 - in sede

pippo - 15/03/2008 - permesso
ciao - 15/03/2008 - in sede
sempronio - 15/03/2008 - in sede

pippo - 22/03/2008 - in sede
caio - 22/03/2008 - malattia


I need another one option:

Quote:
Originally Posted by
11/03/2008 - in sede - 1 rows
11/03/2008 - operatore - 1 rows

12/03/2008 - operatore - 1 rows
12/03/2008 - ferie - 1 rows

13/03/2008 - ferie - 2 rows

14/03/2008 - in sede - 2 rows
14/03/2008 - permesso - 1 rows

15/03/2008 - permesso - 1 rows
15/03/2008 - in sede - 2 rows

22/03/2008 - in sede - 1 rows
22/03/2008 - malattia - 1 rows


I'm explain you ?

Reply
viki1967's Avatar
viki1967
Familiar Sight
164 Posts
March 26th, 2008
08:28 PM
#3

Re: [ASP and MySQL] Paging
Hi there.

This is the solution: ;)

Code: ( text )
  1. baseQuery = " SELECT * "
  2. baseQuery = baseQuery & " , COUNT(Tipo)"
  3. baseQuery = baseQuery & " AS totale_Tipo "
  4. baseQuery = baseQuery & " FROM "
  5. baseQuery = baseQuery & " tbl "
  6. baseQuery = baseQuery & " GROUP BY "
  7. baseQuery = baseQuery & " Tipo,"
  8. baseQuery = baseQuery & " Data "
  9.  
  10. q1 = " SELECT "
  11. q1 = q1 & " COUNT(*) FROM "
  12. q1 = q1 & " ( SELECT DISTINCT "
  13. q1 = q1 & " Tipo, "
  14. q1 = q1 & " Data "
  15. q1 = q1 & " FROM "
  16. q1 = q1 & " tbl ) "
  17. q1 = q1 & " tbl "
  18.  
  19. q2 = baseQuery & " ORDER BY "
  20. q2 = q2 & " DataOperazione ASC "
  21. q1 = q1 & " LIMIT " & (currentPage - 1) * pageSize & ", "
  22. q1 = q1 & " " & pageSize


Bye....

Reply
Reply
Not the answer you were looking for? Post your question . . .
180,431 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top ASP Forum Contributors