PDA

View Full Version : help in sort


bmwmpower
04-15-2003, 03:57 PM
i have problem with sort this is my code i see it work with only

id and dateadded but name amd node_cluster and time_spend not work why i don't know


========================================
sql = sql & "ORDER BY "
Select Case Trim(LCase(Request("sortby")))
Case "Name": sql = sql & "Name"
Case "Node_cluster": sql = sql & "Node_cluster"
Case "Time_spend": sql = sql & "Time_spend"
Case "Dateadded": sql = sql & "Dateadded"
Case Else: sql = sql & "ID "
End Select

'--Sort Order
Select Case Trim(LCase(Request("sortorder")))
Case "desc": sql = sql & "DESC"
Case Else: sql = sql & "ASC"
End Select
================================

<select accesskey="b" name="sortby">
<option value="id">ID</option>
<option value="name"<%If Trim(LCase(Request("sortby"))) = "name" Then Response.Write " selected"%>>Name</option>
<option value="Node_cluster"<%If Trim(LCase(Request("sortby"))) = "node_cluster" Then Response.Write " selected"%>>Node_cluster</option>
<option value="Time_spend"<%If Trim(LCase(Request("sortby"))) = "time_spend" Then Response.Write " selected"%>>Time_spend</option>
<option value="Dateadded"<%If Trim(LCase(Request("sortby"))) = "dateadded" Then Response.Write " selected"%>>Dateadded</option>
</select>
&nbsp;
<select name="sortorder">
<option value="asc">Ascending</option>
<option value="desc"<%If Trim(LCase(Request("sortorder"))) = "desc" Then Response.Write " selected"%>>Descending</option>
</select>

Spudhead
04-15-2003, 04:19 PM
Try response.write() the SQL statement - then run it directly against your database. Any SQL errors will show up there (you might have a problem with missing spaces? Not sure.)

raf
04-15-2003, 04:21 PM
Hmm, did you look at the sql statement that was actually build?
by placing
response.write sql
response.end
before executing the statement?
Are you sure the variablenames are correct?
<edit>posts crossed</edit>

bmwmpower
04-15-2003, 04:26 PM
sorry iam new so tell me how ???
give me example

raf
04-15-2003, 07:42 PM
You have this piece of code

Select Case Trim(LCase(Request("sortorder")))
Case "desc": sql = sql & "DESC"
Case Else: sql = sql & "ASC"
End Select
================================


Now, if you insert this

response.write sql
response.end


Right after it (assuming you don't alter the sql statement later on) and you request this page in your browser, then you will see the sql statement like it is executed. You can then see if it is build correctly