PDA

View Full Version : why i cant search any record in the second page of my paging?(ASP)


yen
08-28-2006, 02:52 PM
hello.i m a ASP beginner. i m doing a recordset paging from the record in database. at first, i have one page that pass the varibale "category" to 2nd page, and the varibale store in <input type="hidden">. and then in the 2nd page, it will display all the product record about that category i choose from the drop down menu at first page. in the 2nd page, there have a paging for the record, and then above got one search by field function. i can search the record from the same category on the first page, but when i click on the 2nd page and so on, i cant search any record from the same category. when i go back to the first page again, i still cant search any record. do u know what is the problem?cant pass the search parameter?can someone teach me and help me solve this problem?i m in urgent to solve it.i will attach my two file code. i hope some one who is kind..can help me..thanx a lot.

[daftarstok.asp]
<!-- #include file="..\Connection\connect.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>
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="Semak" style="background:#f5f5f5">
</center>
</form>
<%
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
%>


[daftarstok3.asp]
<%
FUNCTION ConvertDbl(input)
if Len(input)>0 AND ISNUMERIC(input)=True then
ConvertDbl=CDbl(Trim(input))
else
ConvertDbl=0
end if
end function
%>
<%
iPagesize=4
If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = ConvertDbl(Request.QueryString("page"))
End If


%>

<!-- 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" value="<%=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">Kod Bar </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">Jenis 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,Category


Category = Request("category")'change this to pass the variable category for the paging
search=request("search")

search = trim(Replace(request("search"),"'",""""))
field=request.form("field")
response.write field &"<br>"
response.write search &"<br>"

Dim rs, sql

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

if search<>"" then
sql="SELECT * FROM ProductMKP, ProductType where ProductType.TypeID=ProductMKP.TypeID AND "&field&" LIKE '%%" &search& "%%'AND ProductMKP.TypeID='"&category&"' "
response.write sql &"<br>"
else

sql= "Select ProductMKP.*, ProductType.Type FROM ProductMKP,ProductType WHERE ProductType.TypeID=ProductMKP.TypeID AND ProductMKP.TypeID='"&category&"' Order By ProductDescription"
response.write sql &"<br>"
end if

rs.PageSize = iPageSize
rs.CacheSize = iPageSize

rs.Open sql, conn,3,2,1
iPageCount = rs.PageCount

If iPageCurrent > iPageCount Then
iPageCurrent = iPageCount
End If

If iPageCurrent < 1 Then
iPageCurrent = 1
End If


%>
<br/>

<table width="666" border="1" onMouseover="changeto(event, '#c5ddf9')" onMouseout="changeback(event, '#E7Ecf3')">
record count:[<font color="red"><b><%=ConvertDbl(rs.RecordCount)%></b></font>]
<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>Nama 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>
<%
if rs.RecordCount>0 then
i=1
rs.AbsolutePage=iPageCurrent
iRecordsShown = 0

do while not rs.EOF and iRecordsShown<iPageSize
%>


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

</tr>

<%

iRecordsShown=iRecordsShown+1
rs.movenext
i=i+1
loop

end if

%>
</table>
<% if Rs.recordcount =0 then %>
<tr>
<td colspan="6" class="arial11red " align="center" height="18"><b><font color="red" class="FredLight8Normal">
--- Tiada Rekod ---</font></b>
</td>
</tr>
<% end if %>
<tr>
<td colspan="6" class="arial11red " align="center" height="12">
<%If Rs.RecordCount > 0 Then%>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%">
<tr>
<td nowrap valign="middle" width="100%" colspan="4" height="6">
</td>
</tr>

<tr>
<td width="100%" height="37" valign="middle" nowrap><sub>Current Page: [ <%=iPageCurrent%>/<%=iPageCount%> ]</sub></td>
<%If iPageCurrent > 1 Then%>
<td nowrap valign="middle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="<%=Request.Servervariables("script_name")%>?page=<%=Server.URLEncode(iPageCurrent-1)%>&Category=<%=category%>&search=<%=search%>"style ='color:#336699'">Previos</a>&nbsp;&nbsp;&nbsp;
</td>
<%End If%>
<td nowrap valign="middle">
<%For i = 1 To iPageCount%>
<%If i = iPageCurrent Then%>
<b>[<%=i%>]</b>
<%Else%>

<a href="<%=Request.Servervariables("Script_Name")%>?page=<%=Server.URLEncode(i)%>&Category=<%=category%>&search=<%=search%>"style ='color:#336699'class="innerbodylink"><b><%=i%></b></a>

<%End If%>
<%Next%>
</td>
<%If iPageCurrent < iPageCount Then%>
<td nowrap valign="middle">&nbsp;&nbsp;&nbsp;<a href="<%=Request.Servervariables("Script_Name")%>?page=<%=Server.URLEncode(iPageCurrent+1)%>&Category=<%=category%>&search=<%=search%>"style ='color:#336699'">Next Page</a>
</td>
<%End If%>
<%End if%>
<%Set rs = Nothing%>

</tr>
</table>
</td>
</tr>

</div>
<div id="Layer1" style="position:absolute; width:161px; height:25px; z-index:12; left: 761px; top: 144px; visibility: visible;"> <A HREF="juruMKP.asp" target="_parent"><FONT COLOR="#336699">Halaman utama</font></A><FONT COLOR="#336699"> &nbsp;|&nbsp; <A HREF="logout.asp" target="_parent"><FONT COLOR="#336699">Keluar</font></A> </font></div>
<div id="Layer3" style="position:absolute; width:100px; height:26px; z-index:13; left: 733px; top: 242px;">
<form>
<input type="button" value=" Kategori Lain" size="20" style="background:#f5f5f5" onclick="self.location='daftarstok.asp'">
</form>

Wylie
08-29-2006, 05:13 AM
Honestly, it is hard to check error without testing.
What I found an error is on db connection; you are using connect.asp to connect the db, but you are missing this file in daftarstok3.asp. However, it sounds bad for me that creating a file for db connect. If you still cannot connect db on the page of daftarstok3.asp, you may better to put the code that within connect.asp back.