Forums

This topic is locked

ORDER BY sql

Posted 19 Jul 2007 04:14:18
1
has voted
19 Jul 2007 04:14:18 0 0 posted:
Form on the search page passes the results to results page. Everything works fine except ORDER BY part in a sql on a result's page.
I'm using Access database and Dreamveaver 8.0.2. Can anybody please suggest solution to get the ORDER BY to work.
This is the form o search page:
<pre id=code><font face=courier size=2 id=code>&lt;form action="results.asp" method="post" name="search1" id="search1"&gt;
&lt;input name="use" type="radio" value="Prodajem" /&gt;Prodajem&lt;/td&gt;
&lt;input name="use" type="radio" value="Kupujem" /&gt;Kupujem&lt;/td&gt;


&lt;input name="type" type="radio" value="ku&#263;u" /&gt;ku&#263;u&lt;/td&gt;
&lt;input name="type" type="radio" value="poslovni prostor" /&gt;poslovni prostor&lt;/td&gt;


&lt;select name="zupanija" class="style2" id="zupanija"&gt;
&lt;option value="%"&gt;Sve &#382;upanije...&lt;/option&gt;
&lt;option value="Zagreb i Zagreba&#269;ka"&gt;Zagreb i Zagreba&#269;ka&lt;/option&gt;
&lt;option value="Dubrova&#269;ko-neretvanska"&gt;Dubrova&#269;ko-neretvanska&lt;/option&gt;
&lt;option value="Splitsko-dalmatinska"&gt;Splitsko-dalmatinska&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;

&lt;input name="grad" type="text" class="style3" id="grad" size="20" /&gt;&lt;/td&gt;

&lt;select name="cijenaod" class="style2" id="cijenaod"&gt;
&lt;option value="0"&gt;0&lt;/option&gt;
&lt;option value="500"&gt;500&lt;/option&gt;
&lt;option value="1000"&gt;1000&lt;/option&gt;
&lt;option value="5000"&gt;5000&lt;/option&gt;
&lt;option value="10000"&gt;10000&lt;/option&gt;
&lt;/select&gt;

&lt;select name="cijenado" class="style2" id="cijenado"&gt;
&lt;option value="50000000"&gt;Nije va&#382;no&lt;/option&gt;
&lt;option value="500"&gt;500&lt;/option&gt;
&lt;option value="1000"&gt;1000&lt;/option&gt;
&lt;option value="5000"&gt;5000&lt;/option&gt;
&lt;option value="10000"&gt;10000&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;

&lt;select name="soba" class="style2" id="soba"&gt;
&lt;option value="%"&gt;Nije va&#382;no...&lt;/option&gt;
&lt;option value="1"&gt;1&lt;/option&gt;
&lt;option value="2"&gt;2&lt;/option&gt;
&lt;option value="3"&gt;3&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;

&lt;input name="sort" type="radio" value="ASC" /&gt;
&lt;input name="sort" type="radio" value="DESC" /&gt;

&lt;input name="Submit" type="submit" class="style8" value="Tra&#382;i" /&gt;

&lt;/form&gt;</font id=code></pre id=code>

Code for the results page is:
<pre id=code><font face=courier size=2 id=code>&lt;%
Dim rsResults__cijenaod
rsResults__cijenaod = "0"
If (Request.Form("cijenaod" &lt;&gt; "" Then
rsResults__cijenaod = Request.Form("cijenaod"
End If
%&gt;
&lt;%
Dim rsResults__cijenado
rsResults__cijenado = "50000000"
If (Request.Form("cijenado" &lt;&gt; "" Then
rsResults__cijenado = Request.Form("cijenado"
End If
%&gt;
&lt;%
Dim rsResults__use
rsResults__use = "%"
If (Request.Form("use" &lt;&gt; "" Then
rsResults__use = Request.Form("use"
End If
%&gt;
&lt;%
Dim rsResults__type
rsResults__type = "%"
If (Request.Form("type" &lt;&gt; "" Then
rsResults__type = Request.Form("type"
End If
%&gt;
&lt;%
Dim rsResults__zupanija
rsResults__zupanija = "%"
If (Request.Form("zupanija" &lt;&gt; "" Then
rsResults__zupanija = Request.Form("zupanija"
End If
%&gt;
&lt;%
Dim rsResults__soba
rsResults__soba = "%"
If (Request.Form("soba" &lt;&gt; "" Then
rsResults__soba = Request.Form("soba"
End If
%&gt;
&lt;%
Dim rsResults__grad
rsResults__grad = "%"
If (Request.Form("grad" &lt;&gt; "" Then
rsResults__grad = Request.Form("grad"
End If
%&gt;
&lt;%
Dim rsResults__sort
rsResults__sort = "ASC"
If (Request.Form("sort" &lt;&gt; "" Then
rsResults__sort = Request.Form("sort"
End If
%&gt;
&lt;%
Dim rsResults
Dim rsResults_cmd
Dim rsResults_numRows

Set rsResults_cmd = Server.CreateObject ("ADODB.Command"
rsResults_cmd.ActiveConnection = MM_mm_web_STRING
rsResults_cmd.CommandText = "SELECT * FROM mm_property WHERE (p_price BETWEEN ? AND ?) AND (p_use LIKE ?) AND (p_type LIKE ?) AND p_county LIKE ? AND p_rooms LIKE ? AND p_town LIKE ? ORDER BY p_price ?"
rsResults_cmd.Prepared = true
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param1", 5, 1, -1, rsResults__cijenaod) ' adDouble
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param2", 5, 1, -1, rsResults__cijenado) ' adDouble
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param3", 200, 1, 255, rsResults__use) ' adVarChar
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param4", 200, 1, 255, rsResults__type) ' adVarChar
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param5", 200, 1, 255, rsResults__zupanija) ' adVarChar
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param6", 200, 1, 255, rsResults__soba) ' adVarChar
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param7", 200, 1, 255, rsResults__grad) ' adVarChar
rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param8", 5, 1, -1, rsResults__sort) ' adDouble

Set rsResults = rsResults_cmd.Execute
rsResults_numRows = 0
%&gt;</font id=code></pre id=code>


Above code works fine in Dreamveaver 8.0.2 but on server it results in an error "Application uses a value of the wrong type" pointing to the line: <pre id=code><font face=courier size=2 id=code>rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param8", 5, 1, -1, rsResults__sort) ' adDouble</font id=code></pre id=code>

Please help.

Warm regards.

Replies

Replied 24 Jul 2007 06:24:46
24 Jul 2007 06:24:46 Patrick Woldberg replied:
Try changing the query to:
<pre id=code><font face=courier size=2 id=code>rsResults_cmd.CommandText = "SELECT * FROM mm_property WHERE (p_price BETWEEN ? AND ?) AND (p_use LIKE ?) AND (p_type LIKE ?) AND p_county LIKE ? AND p_rooms LIKE ? AND p_town LIKE ? ORDER BY p_price " & rsResults__sort</font id=code></pre id=code>
and remove the line:
<pre id=code><font face=courier size=2 id=code>rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param8", 5, 1, -1, rsResults__sort) ' adDouble</font id=code></pre id=code>

The sort order can not be passed as parameter, it requires a string, but the createParameter will always put quotes arround string which causes it not to work. Passing the parameter as number will also not work because the type is being checked and it will give an error like you noticed.

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Administrator at DMXzone.com, FLzone.net, FWzone.net and DNzone.com
--------------------------------------------------
Replied 24 Jul 2007 19:17:12
24 Jul 2007 19:17:12 0 0 replied:
tryed your suggestion and it returns an error:
<pre id=code><font face=courier size=2 id=code>Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 8.
/mm_web/results.asp, line 91</font id=code></pre id=code>
line 91 is:
<pre id=code><font face=courier size=2 id=code>...
87 rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param5", 200, 1, 255, rsResults__zupanija) ' adVarChar
88 rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param6", 200, 1, 255, rsResults__soba) ' adVarChar
89 rsResults_cmd.Parameters.Append rsResults_cmd.CreateParameter("param7", 200, 1, 255, rsResults__grad) ' adVarChar
90
91 Set rsResults = rsResults_cmd.Execute</font id=code></pre id=code>

Would appreciate other suggestions.

Thanks for the effort.

Reply to this topic