Web Analytics Made Easy -
StatCounter Sort my recordset records alphabiitcally - CodingForum

Announcement

Collapse
No announcement yet.

Sort my recordset records alphabiitcally

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sort my recordset records alphabiitcally

    Hey guys, I have a recordset, a repeat region and a select tag (drop down), options repeat in a repeat region and everything works fine but there is still a little problem here, i can manage to sort course_title records (options) by id (ASC or DESC) but I don't want that I want the course_title records to sort by alphabetical order from a-z.

    My table image attached to this post (as you see in that image i want course_title to sort alphabetically).


    Here is my recordset and repeat region

    Code:
    <%
    Dim rs_cat
    Dim rs_cat_cmd
    Dim rs_cat_numRows
    
    Set rs_cat_cmd = Server.CreateObject ("ADODB.Command")
    rs_cat_cmd.ActiveConnection = MM_admin_ivu_STRING
    rs_cat_cmd.CommandText = "SELECT * FROM dbo.cat_course ORDER BY course_ID DESC" 
    rs_cat_cmd.Prepared = true
    
    Set rs_cat = rs_cat_cmd.Execute
    rs_cat_numRows = 0
    %>
    
    
    <%
    Dim Repeat1__numRows
    Dim Repeat1__index
    
    Repeat1__numRows = -1
    Repeat1__index = 0
    rs_notice_numRows = rs_notice_numRows + Repeat1__numRows
    %>


    Here is my select tag and option with repeating region:

    Code:
    <select name="course_ID" class="styled" id="">
    <option value=""  selected="selected" class="height_options" disabled="disabled" onchange="callSite(this)">&lt;&lt;&lt; Please Choose Category &gt;&gt;&gt;</option>
    
    <%
    While (NOT rs_cat.EOF)
    %>
    
    <option value="<%=(rs_cat.Fields.Item("course_ID").Value)%>" class="height_options"><%=(rs_cat.Fields.Item("course_title").Value)%></option>
    
    <%
    rs_cat.MoveNext()
    Wend
    If (rs_cat.CursorType > 0) Then
    rs_cat.MoveFirst
    Else
    rs_cat.Requery
    End If
    %>
    
    </select>

    Thanks folks ...
    Attached Files
    Last edited by Datis; Sep 9, 2011, 04:21 AM.

  • #2
    So change the query.

    Code:
    rs_cat_cmd.CommandText = "SELECT * FROM dbo.cat_course ORDER BY [B][COLOR="Red"]course_title ASC[/COLOR][/B]"
    That code is typical DreamWeaver code (or, as I prefer to call it, NightmareStalker code).

    Bloated and inefficient and all. If you care, you could streamline it a *lot*.

    *ALL* the code you showed in your post (all of it) could be shrunk to this:
    Code:
    <select name="course_ID" class="styled" id="">
    <option value=""  selected="selected" class="height_options" disabled="disabled" onchange="callSite(this)">&lt;&lt;&lt; Please Choose Category &gt;&gt;&gt;</option>
    <%
    Set RS = Server.CreateObject ("ADODB.Recordset")
    SQL = "SELECT course_id, course_title FROM dbo.cat_course ORDER BY course_title ASC" 
    RS.Open SQL, MM_admin_ivu_STRING
    Do Until RS.EOF
    %>
    <option value="<%=RS("course_ID")%>" class="height_options"><%=RS("course_title")%></option>
    <%
        RS.MoveNext()
    Loop
    RS.Close
    %>
    </select>
    (And with a minor change to your CSS it could be even simpler.)
    Be yourself. No one else is as qualified.

    Comment


    • #3
      Oops...just noticed this:
      Code:
      <select name="course_ID" class="styled" [B][COLOR="Red"]id=""[/COLOR][/B]>
      A blank ID is illegal. Get rid of it. It's not doing anything.
      Be yourself. No one else is as qualified.

      Comment


      • #4
        And the onchange is in the wrong place! It needs to be on the <select>, *NOT* on the first <option>!

        Okay, rewrite time.
        Code:
        <style type="text/css">
        select.styled {
            ... whatever you have there now ...
        }
        select.styled option {
            ... whatever is currently in your [b]height_options[/b] class...
        }
        </style>
        ...
        <select name="course_ID" class="styled" onchange="callSite(this)">
        <option value=""  selected="selected" disabled="disabled" >&lt;&lt;&lt; Please Choose Category &gt;&gt;&gt;</option>
        <%
        Set RS = Server.CreateObject ("ADODB.Recordset")
        SQL = "SELECT course_id, course_title FROM dbo.cat_course ORDER BY course_title ASC" 
        RS.Open SQL, MM_admin_ivu_STRING
        Do Until RS.EOF
            Response.Write "<option value=""" & RS("course_ID") & """>" & RS("course_title") & "</option>" & vbNewLine
            RS.MoveNext()
        Loop
        RS.Close
        %>
        </select>
        Because the onchange was on the <option> (which might work in some browsers, but not in all!) you might need to change the call in the <select> to
        Code:
        <select name="course_ID" class="styled" onchange="callSite(this[COLOR="Red"].options[0][/COLOR])">
        Can't tell without seeing the JavaScript code.
        Be yourself. No one else is as qualified.

        Comment


        • #5
          Originally posted by Old Pedant View Post
          So change the query.

          Code:
          rs_cat_cmd.CommandText = "SELECT * FROM dbo.cat_course ORDER BY [B][COLOR="Red"]course_title ASC[/COLOR][/B]"
          That code is typical DreamWeaver code (or, as I prefer to call it, NightmareStalker code).

          Bloated and inefficient and all. If you care, you could streamline it a *lot*.

          *ALL* the code you showed in your post (all of it) could be shrunk to this:
          Code:
          <select name="course_ID" class="styled" id="">
          <option value=""  selected="selected" class="height_options" disabled="disabled" onchange="callSite(this)">&lt;&lt;&lt; Please Choose Category &gt;&gt;&gt;</option>
          <%
          Set RS = Server.CreateObject ("ADODB.Recordset")
          SQL = "SELECT course_id, course_title FROM dbo.cat_course ORDER BY course_title ASC" 
          RS.Open SQL, MM_admin_ivu_STRING
          Do Until RS.EOF
          %>
          <option value="<%=RS("course_ID")%>" class="height_options"><%=RS("course_title")%></option>
          <%
              RS.MoveNext()
          Loop
          RS.Close
          %>
          </select>
          (And with a minor change to your CSS it could be even simpler.)
          Originally posted by Old Pedant View Post
          And the onchange is in the wrong place! It needs to be on the <select>, *NOT* on the first <option>!

          Okay, rewrite time.
          Code:
          <style type="text/css">
          select.styled {
              ... whatever you have there now ...
          }
          select.styled option {
              ... whatever is currently in your [b]height_options[/b] class...
          }
          </style>
          ...
          <select name="course_ID" class="styled" onchange="callSite(this)">
          <option value=""  selected="selected" disabled="disabled" >&lt;&lt;&lt; Please Choose Category &gt;&gt;&gt;</option>
          <%
          Set RS = Server.CreateObject ("ADODB.Recordset")
          SQL = "SELECT course_id, course_title FROM dbo.cat_course ORDER BY course_title ASC" 
          RS.Open SQL, MM_admin_ivu_STRING
          Do Until RS.EOF
              Response.Write "<option value=""" & RS("course_ID") & """>" & RS("course_title") & "</option>" & vbNewLine
              RS.MoveNext()
          Loop
          RS.Close
          %>
          </select>
          Because the onchange was on the <option> (which might work in some browsers, but not in all!) you might need to change the call in the <select> to
          Code:
          <select name="course_ID" class="styled" onchange="callSite(this[COLOR="Red"].options[0][/COLOR])">
          Can't tell without seeing the JavaScript code.
          Originally posted by Old Pedant View Post
          Oops...just noticed this:
          Code:
          <select name="course_ID" class="styled" [B][COLOR="Red"]id=""[/COLOR][/B]>
          A blank ID is illegal. Get rid of it. It's not doing anything.

          Wow those were really great, thanks for that man, Btw DW is truly a nightmare (I do believe in it too) but cant afford to leave it (it drugs me every time I use it ) I resolved all of those thanks to your key expertise

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎