944,184 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 1479
  • ASP RSS
Aug 25th, 2006
0

searching and paging..plz help..

Expand Post »
sorry..i have to expalin again about my code.
at my frist page, i populate a drop down menu list from a database. when the user drop down the menu and choose the category (daftarstok.asp), it will display all the record that related on the 2nd pages (daftarstok3.asp). and then..on the 2nd page, users can search the keyword such as bar code, serial num, asset num(multiple field search) jz for tat category that have choose before. mean..it will not search the other product for the other category. but....if i can do the search, i cant do the paging.when i click on the number paging for 2nd page,it cant display any record. i will attach my code. plz help me .....i really have no idea..plz..in urgent also..plz


[daftarstok.asp]
<%
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")

sql="Select * From ProductType order by TypeID"
rs.Open sql,conn

'jika bukan tiada record
If Not rs.EOF Then

%>

<center><font face="Verdana" size="3" color="#336699"></font>
</center>
<form action="daftarstok3.asp" method="post">
<center><select name="category">
<%
Do While Not rs.EOF
TypeID=rs("TypeID")
Category=rs("Type") 'category is the type inside the table
%>
<!--typeId ialah 1,2,3--><!--select from ProductType table-->
<option value="<%= TypeID %>" style="background:#f5f5f5"><%=Category%></option>
<%
'cont search
rs.MoveNext
Loop
%>
</select>

<input type="submit" value="Semak" style="background:#f5f5f5">
</center>
</form>
<%
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
%>

[daftarstok3.asp]
<%
'declare paging variable
dim DisplayNum, i, page,ipage,z, pages
page=request.QueryString("page")
if page="" then
page=1
else page=cInt(page)
End if

DisplayNum=0
%>
<!-- search form by multiple field-->
<table>
<form action="<%=request.servervariables("script name")%>" method="post" name="form1" id="form1">

<input type="hidden" name="category" value="<%=request.form("category")%>">
<tr>
<td>KataKunci Carian:</td>
<td>
<input type="text" name="search" value="<%=search %>"> <!--search value-->
</td>
<td>
<select size="1" name="field"> <!--drop down menu that display multiple field-->
<!--field empty then display all record by default-->
<option
<% if field="BarCode" or field="" then %> selected
<% end if %> value="BarCode">Bar Kod </option>
<option
<% if field="InvoiceNo" then %> selected
<% end if %> value="InvoiceNo">Nombor Invois </option>
<option
<% if field="ProductDescription" then %>selected
<% end if %> value="ProductDescription">Nama Produk </option>

<option
<% if field="AssetTypeVot" then %>selected
<% end if %> value="AssetTypeVot">Vot Aset </option>
</select></td>
<td><input name="submit" type="submit" value="Cari" style="background:#f5f5f5"> <input name="reset" type="reset" value="Padam" style="background:#f5f5f5"></td>
</form>
</tr>
</table>

<%


Dim search,field
ID=Request.queryString ("ID")
search=trim(request.form("search"))
field=trim(request.form("field"))
Dim rs, sql

Set rs = Server.CreateObject("ADODB.Recordset")
if search<>"" then
sql="SELECT * FROM ProductMKP, ProductType where "&field&" LIKE '%%" & search & "%%' AND ProductMKP.TypeID='"& Request.Form("category")&"' AND ProductType.TypeID=ProductMKP.TypeID"
else

sql= "Select ProductMKP.*,ProductType.Type FROM ProductMKP,ProductType WHERE ProductType.TypeID=ProductMKP.TypeID AND ProductMKP.TypeID='" & Request.Form("category")&"' Order By ID"
end if


rs.PageSize=2

rs.Open sql, conn,3,2,1

%>
<br/>
<%if rs.EOF then

response.write "No result found"
observations=0
else
observations=1
ipage=rs.PageCount
if page=0 or page>ipage then
rs.AbsolutePage=ipage
else
rs.AbsolutePage=page
end if
end if

%>

<%if observations > 0 then

%>
<%

%>

<font size="3" face="Time News Roman" color="#336699">Displaying page <%=Page%> of <%=ipage%>:</font>
<table width="666" border="1" onMouseover="changeto(event, '#c5ddf9')" onMouseout="changeback(event, '#E7Ecf3')">

<tr>

<td bgcolor="#97b7de" ><font face="Verdana" size="2"><u><center><b>Kategori</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u> <center><b>Kod Bar</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Nombor Invois</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Jenis Vot Aset</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Produk</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Lihat</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Kemaskini</b></center></u></font></td>
</tr>
<%
rs.movefirst

do while not rs.EOF and DisplayNum <rs.PageSize
%>
<%

response.write "<tr>"

response.write "<td><font face='Verdana' color='black' size=2>" & rs("Type") & "</font></td>"
response.write "<td><font face='Verdana' color='black' size=2>" & rs("BarCode") & "</font></td>"
response.write "<td><font face='Verdana' color='black' size=2>" & rs("InvoiceNo") & "</font></td>"
response.write "<td><font face='Verdana' color='black' size=2>" & rs("AssetTypeVot") & "</font></td>"
response.write "<td><font face='Verdana' color='black' size=2>" & rs("ProductDescription") & "</font></td>"
response.write "<td>" & "<a href='view.asp?ID=" & rs("ID")& "' style ='color:#336699'>Lihat</a> " & "</td>"
response.write "<td>" & "<a href='edit.asp?ID=" & rs("ID")& "'style ='color:#336699'>Edit</a> " & "</td>"
response.write "</tr> "
%>
<%

DisplayNum=DisplayNum+1
iRecordCount=iRecordCount+1
rs.movenext
loop
response.write "<font color='#CD6090'>Kategori ini mempunyai <b>"&iRecordCount&" </b>rekod.</font>"

%>
</table>
<%
end if%>
<%
if ipage>1 then
response.write"<p align=center>"
pages="<font color='#336699' face='Times new roman' size='3'><b>Pages: </b></font>"

for z=1 to ipage
if z=page then
pages=pages & page & " "
else
pages=pages & "<a href=?page=" & z &" style ='color:#336699'>" & z & "</a>" & " "
end if
next
response.write pages & " "
end if

if ipage>1 and page>1 then
response.write"<a href=?page=" & page-1 & " style ='color:green'>Previous </a>"
end if

response.write " "

if ipage>1 and page<ipage then
response.write "<a href=?page="& page+1 & " style ='color:green'> Next </a>"
end if
response.write "</b></p>"
%>
<%

rs.close
set rs=nothing
conn.Close
Set conn = Nothing
%>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kumiko is offline Offline
3 posts
since Apr 2006
Aug 27th, 2006
0

Re: searching and paging..plz help..

Click to Expand / Collapse  Quote originally posted by kumiko ...
sorry..i have to expalin again about my code.
at my frist page, i populate a drop down menu list from a database. when the user drop down the menu and choose the category (daftarstok.asp), it will display all the record that related on the 2nd pages (daftarstok3.asp). and then..on the 2nd page, users can search the keyword such as bar code, serial num, asset num(multiple field search) jz for tat category that have choose before. mean..it will not search the other product for the other category. but....if i can do the search, i cant do the paging.when i click on the number paging for 2nd page,it cant display any record. i will attach my code. plz help me .....i really have no idea..plz..in urgent also..plz


[daftarstok.asp]
<%
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")

sql="Select * From ProductType order by TypeID"
rs.Open sql,conn

'jika bukan tiada record
If Not rs.EOF Then

%>

<center><font face="Verdana" size="3" color="#336699"></font>
</center>
<form action="daftarstok3.asp" method="post">
<center><select name="category">
<%
Do While Not rs.EOF
TypeID=rs("TypeID")
Category=rs("Type") 'category is the type inside the table
%>
<!--typeId ialah 1,2,3--><!--select from ProductType table-->
<option value="<%= TypeID %>" style="background:#f5f5f5"><%=Category%></option>
<%
'cont search
rs.MoveNext
Loop
%>
</select>

<input type="submit" value="Semak" style="background:#f5f5f5">
</center>
</form>
<%
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
%>

[daftarstok3.asp]
<%
'declare paging variable
dim DisplayNum, i, page,ipage,z, pages
page=request.QueryString("page")
if page="" then
page=1
else page=cInt(page)
End if

DisplayNum=0
%>
<!-- search form by multiple field-->
<table>
<form action="<%=request.servervariables("script name")%>" method="post" name="form1" id="form1">

<input type="hidden" name="category" value="<%=request.form("category")%>">
<tr>
<td>KataKunci Carian:</td>
<td>
<input type="text" name="search" value="<%=search %>"> <!--search value-->
</td>
<td>
<select size="1" name="field"> <!--drop down menu that display multiple field-->
<!--field empty then display all record by default-->
<option
<% if field="BarCode" or field="" then %> selected
<% end if %> value="BarCode">Bar Kod </option>
<option
<% if field="InvoiceNo" then %> selected
<% end if %> value="InvoiceNo">Nombor Invois </option>
<option
<% if field="ProductDescription" then %>selected
<% end if %> value="ProductDescription">Nama Produk </option>

<option
<% if field="AssetTypeVot" then %>selected
<% end if %> value="AssetTypeVot">Vot Aset </option>
</select></td>
<td><input name="submit" type="submit" value="Cari" style="background:#f5f5f5"> <input name="reset" type="reset" value="Padam" style="background:#f5f5f5"></td>
</form>
</tr>
</table>

<%


Dim search,field
ID=Request.queryString ("ID")
search=trim(request.form("search"))
field=trim(request.form("field"))
Dim rs, sql

Set rs = Server.CreateObject("ADODB.Recordset")
if search<>"" then
sql="SELECT * FROM ProductMKP, ProductType where "&field&" LIKE '%%" & search & "%%' AND ProductMKP.TypeID='"& Request.Form("category")&"' AND ProductType.TypeID=ProductMKP.TypeID"
else

sql= "Select ProductMKP.*,ProductType.Type FROM ProductMKP,ProductType WHERE ProductType.TypeID=ProductMKP.TypeID AND ProductMKP.TypeID='" & Request.Form("category")&"' Order By ID"
end if


rs.PageSize=2

rs.Open sql, conn,3,2,1

%>
<br/>
<%if rs.EOF then

response.write "No result found"
observations=0
else
observations=1
ipage=rs.PageCount
if page=0 or page>ipage then
rs.AbsolutePage=ipage
else
rs.AbsolutePage=page
end if
end if

%>

<%if observations > 0 then

%>
<%

%>

<font size="3" face="Time News Roman" color="#336699">Displaying page <%=Page%> of <%=ipage%>:</font>
<table width="666" border="1" onMouseover="changeto(event, '#c5ddf9')" onMouseout="changeback(event, '#E7Ecf3')">

<tr>

<td bgcolor="#97b7de" ><font face="Verdana" size="2"><u><center><b>Kategori</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u> <center><b>Kod Bar</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Nombor Invois</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Jenis Vot Aset</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Produk</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Lihat</b></center></u></font></td>
<td bgcolor="#97b7de"><font face="Verdana" size="2" ><u><center><b>Kemaskini</b></center></u></font></td>
</tr>
<%
rs.movefirst

do while not rs.EOF and DisplayNum <rs.PageSize
%>
<%

response.write "<tr>"

response.write "<td><font face='Verdana' color='black' size=2>" & rs("Type") & "</font></td>"
response.write "<td><font face='Verdana' color='black' size=2>" & rs("BarCode") & "</font></td>"
response.write "<td><font face='Verdana' color='black' size=2>" & rs("InvoiceNo") & "</font></td>"
response.write "<td><font face='Verdana' color='black' size=2>" & rs("AssetTypeVot") & "</font></td>"
response.write "<td><font face='Verdana' color='black' size=2>" & rs("ProductDescription") & "</font></td>"
response.write "<td>" & "<a href='view.asp?ID=" & rs("ID")& "' style ='color:#336699'>Lihat</a> " & "</td>"
response.write "<td>" & "<a href='edit.asp?ID=" & rs("ID")& "'style ='color:#336699'>Edit</a> " & "</td>"
response.write "</tr> "
%>
<%

DisplayNum=DisplayNum+1
iRecordCount=iRecordCount+1
rs.movenext
loop
response.write "<font color='#CD6090'>Kategori ini mempunyai <b>"&iRecordCount&" </b>rekod.</font>"

%>
</table>
<%
end if%>
<%
if ipage>1 then
response.write"<p align=center>"
pages="<font color='#336699' face='Times new roman' size='3'><b>Pages: </b></font>"

for z=1 to ipage
if z=page then
pages=pages & page & " "
else
pages=pages & "<a href=?page=" & z &" style ='color:#336699'>" & z & "</a>" & " "
end if
next
response.write pages & " "
end if

if ipage>1 and page>1 then
response.write"<a href=?page=" & page-1 & " style ='color:green'>Previous </a>"
end if

response.write " "

if ipage>1 and page<ipage then
response.write "<a href=?page="& page+1 & " style ='color:green'> Next </a>"
end if
response.write "</b></p>"
%>
<%

rs.close
set rs=nothing
conn.Close
Set conn = Nothing
%>



hello, can someone who know can teach me?????:cry:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kumiko is offline Offline
3 posts
since Apr 2006
Sep 13th, 2006
0

Re: searching and paging..plz help..

Hi Kumiko,

Your code is very lengthy and it's difficult for me to go through it completely.

I suggest something for ur problem..

You want to keep paging intact while you search. right?
if this is the case then here go

pass the pageno. querystring whenever you are searching. this helps you keeping pageno. intact.

keep the pageno. in a variable and assign it to a hidden value.
you can always retrieve the pageno. from the hidden value.

Hope this works.
Thanks,
Chaitanya.
Reputation Points: 11
Solved Threads: 1
Light Poster
chmonalisa is offline Offline
26 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Login failed
Next Thread in ASP Forum Timeline: how do I control multiple instances of the client browser





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC