PDA

View Full Version : سوال: خوندن رکورد از بانک



night star
شنبه 07 شهریور 1388, 12:49 عصر
سلام
من می خوام از بانک فقط یکسری رکوردهای مخصوص از بانک خونده بشه
مثلا از رکورد شماره 1 تا 6 تو یک صفحه خونده بشه و واز رکورد شماره 6 تا 12 تو صفحه دیگه می شه راهنمایی کنید

aryaei2000
شنبه 07 شهریور 1388, 13:20 عصر
فکر کنم منظورتون paging باشه.لینک های زیر میتونه کمکت کنه.
http://www.theukwebdesigncompany.com/articles/article.php?article=598
http://www.stardeveloper.com/articles/display.html?article=2000071001&page=1
http://www.aspin.com/home/tutorial/database/display/pagingre
http://www.codeproject.com/KB/database/rspaging.aspx
http://www.daniweb.com/forums/thread29525.html
سوالی بود بپرس

night star
شنبه 07 شهریور 1388, 14:39 عصر
این ها که خیلی سخته روش آسونتری نیست یا اگه می شه یک کم بیشتر توضیح بدید

aryaei2000
شنبه 07 شهریور 1388, 15:08 عصر
باشه من کامل توضیح میدم.
اول یک دیتا بیس اکسس بسازید بنام Sample.mdb
بعدش یه جدول بنام Employee با فیلد هایی از قبیل ID و Name و Address.
ID رو بعنوان Autonumber قرار بدید.
20 تا رکورد دلخاه هم به جدول اضافه کنید.
سپس کد های زیر رو در فایلی بنام ASP_Paging.asp ذخیره کنید.


<@ language=vbscript @>
<!--#include file=paging_inc.asp-->
<%
dim Rst
set Rst=server.CreateObject"ADODB.recordset")
Rst.Open "select * from employee",Connect,3,1,1
if Rst.EOF =true then
Response.Write "No Records Avialable in the Database"
else
dim intPageSize,PageIndex,TotalPages
dim RecordCount,RecordNumber,Count intpageSize=5
PageIndex=request("PageIndex")
if PageIndex="" then
PageIndex=1 RecordCount=Rst.RecordCount
RecordNumber=(intPageSize * PageIndex) - intPageSize
Rst.PageSize =intPageSize
Rst.AbsolutePage = PageIndex TotalPages=Rst.PageCount
dim intPrev,intNext intPrev=PageIndex - 1 intNext=PageIndex +1
Count=1
Response.Write "<table align=center>"
response.write "<tr bgcolor=yellow><th>ID</th><th>Name</th><th>Address</th></tr>"
while not Rst.eof and Count<=intPageSize
response.write "<tr>
<td>" & Rst.fields(0) & "</td><td>" & Rst.fields(1) & "</td><td>" & Rst.fields(2) & "</td></tr>"
Rst.movenext
Count=Count +1
wend
response.write "</table>"
call button(intPrev,intNext,TotalPages)
set Rst=nothing
Connect.close
end if
%>

کدهای زیر رو هم در فایلی بنام Paging_inc.asp ذخیره کنید.

<%
Sub button(intPrev,intNext,TotalPages)
dim Counter
if intPrev <> 0 then
response.write "<a href=ASP_Paging.asp?PageIndex=" & intPrev & ">Previous Page</a>"
end if
if Rst.AbsolutePage <> -3 then
response.write "<a href=ASP_PAging.asp?PageIndex=" & intNext & ">
Next Page </a>"
end if
Counter=1
response.write "<br>Navigate to Page :"
While Counter <=TotalPages
if cint(Counter)=cint(PageIndex) then
response.write Counter
else
response.write "<a href=ASP_Paging.asp?PageIndex=" & Counter & ">" & Counter & "</a>"
end if

if cint(Counter) <> cint(TotalPages) then
response.write " | "
End if
Counter= Counter +1
wend
End Sub

Function Connect()
set Connect=server.createobject("ADODB.connection")
Connect.open "Provider=microsoft.jet.oledb.4.0;Data source=" & server.mappath("Sample.mdb")
End Function
%>

فراموش نکنید که فایل دیتا بیس باید در کنار دو فایل دیگه در یک فلدر قرار بگیره.
حالا صفحه ASP_Paging.asp رو اجرا کنید.

موفق باشید

night star
شنبه 07 شهریور 1388, 15:34 عصر
تمام این کارها رو انجام دادم و لی فایل اجرا نمی شه
می شه در مورد خود paging یک توضیح بدید :ناراحت:

با سپاس فراوان

aryaei2000
شنبه 07 شهریور 1388, 19:45 عصر
فکر کنم این syntax highlighter کا رو خراب کرده.
یه بار دیگه امتحان کنید.


<%
Sub button(intPrev,intNext,TotalPages)
dim Counter
if intPrev <> 0 then
response.write "<a href=ASP_Paging.asp?PageIndex=" & intPrev & ">Previous Page</a>"
end if
if Rst.AbsolutePage <> -3 then
response.write "<a href=ASP_PAging.asp?PageIndex=" & intNext & ">Next Page </a>"
end if
Counter=1
response.write "<br>Navigate to Page :"
While Counter <=TotalPages
if cint(Counter)=cint(PageIndex) then
response.write Counter
else
response.write "<a href=ASP_Paging.asp?PageIndex=" & Counter & ">" & Counter & "</a>"
end if

if cint(Counter) <> cint(TotalPages) then
response.write " | "
End if
Counter= Counter +1
wend
End Sub

Function Connect()
set Connect=server.createobject("ADODB.connection")
Connect.open "Provider=microsoft.jet.oledb.4.0;Data source=" & server.mappath("Sample.mdb")
End Function
%>

و


<@ language=vbscript @>
<!--#include file=paging_inc.asp-->
<%
dim Rst
set Rst=server.CreateObject"ADODB.recordset")
Rst.Open "select * from employee",Connect,3,1,1
if Rst.EOF =true then
Response.Write "No Records Avialable in the Database"
else
dim intPageSize,PageIndex,TotalPages
dim RecordCount,RecordNumber,Count intpageSize=5
PageIndex=request("PageIndex")
if PageIndex="" then
PageIndex=1 RecordCount=Rst.RecordCount
RecordNumber=(intPageSize * PageIndex) - intPageSize
Rst.PageSize =intPageSize
Rst.AbsolutePage = PageIndex TotalPages=Rst.PageCount
dim intPrev,intNext intPrev=PageIndex - 1 intNext=PageIndex +1
Count=1
Response.Write "<table align=center>"
response.write "<tr bgcolor=yellow><th>ID</th><th>Name</th><th>Address</th></tr>"
while not Rst.eof and Count<=intPageSize
response.write "<tr><td>" & Rst.fields(0) & "</td><td>" & Rst.fields(1) & "</td><td>" & Rst.fields(2) & "</td></tr>"
Rst.movenext
Count=Count +1
wend
response.write "</table>"
call button(intPrev,intNext,TotalPages)
set Rst=nothing
Connect.close
end if
%>

paging عبارتست از نمایش اطلاعات در چند صفحه شماره گذاری شده بصورت داینامیک.

night star
یک شنبه 08 شهریور 1388, 09:35 صبح
:ناراحت:
این خطارو میده من خیلی سعی کردم مشکلشو حل کنم ولی نتونستم
این خطارو میده



Microsoft VBScript compilation error '800a0401'
Expected end of statement
/ASP_Paging.asp, line 11
dim RecordCount,RecordNumber,Count intpageSize=5