ASP Paging on a searched memo field

Ask a Question related to ASP, Design and Development.

  1. #1

    Default ASP Paging on a searched memo field

    I need advice on how to integrate the paging capbility to my search
    script. The program I built requires me to make word search on several
    db fields including one that's a memo type field, which doesn't work
    with just a LIKE statement.
    I was doing OK up till the part where I needed to page the results.
    Here the code that I used (note that the code doesn't have paging
    yet):

    ===== start code =====

    ' generate sql for search
    if request.form("btnSubmit") = "Search" then
    strTitle = request.form("fldTitle") 'subject field
    strContent = lcase(request.form("fldContent")) 'news content field

    'generate sql
    strSqlsearch = "select * from News "
    if strTitle <> "" then
    strSqlsearch = strSqlsearch & "where Subject like '%" &
    strTitle & "%' "
    else
    strSqlsearch = strSqlsearch & "and Subject like '%" &
    strTitle & "%' "
    end if
    strSqlsearch = strSqlsearch & "order by id desc"

    ' run sql search
    SQLstatement = strSqlsearch
    set rs = conn.Execute(SQLstatement)

    ' get ready to display
    if rs.eof then
    ' display not found msg
    response.write "<p>No info matches your search.</p>"
    else
    ' write out results
    do while not rs.eof
    ' chg memo field to string
    strContentrs = lcase(rs("Content"))
    ' check if contains keyword for content
    if instr(strContentrs, strContent) > 0 then
    response.write "some stuff to be written"
    end if
    rs.movenext
    loop
    end if
    end if

    ===== end code =====

    Again, could someone advise me how to go about paging this?
    Hate Spam Guest

  2. Similar Questions and Discussions

    1. Searched Datagrid with Paging?
      I am new to .NET, so bear with me. I have a datagrid with default paging of 10. I can page through it fine to the end. When I do a search from a...
    2. Detecting MEMO field
      Hi all, i'd like to know if there is some way to detect whether a field is of type MEMO (i'm using MS Access) so to behave accordingly placing a...
    3. Memo Field vs. OLE Obj
      > is there any appreciable difference between using a field If it's just TEXT, use Memo (or better yet, store the RTF file in the file system). ...
    4. MS Access Memo Field and ASP
      I have a memo field in a MS Access table. The contents of the field may look like this: 1. This is number one 2. This is number 2 3. Skipping...
    5. Memo field behavior
      Hello, In one application I can hit ctrl enter and get a new paragraph and in the second application I cannot. Both are memo fields. The only...
  3. #2

    Default Re: ASP Paging on a searched memo field

    > > Again, could someone advise me how to go about paging this?
    >
    > Here's an article on paging that might help you get started...
    > [url]http://www.aspfaq.com/2120[/url]
    Thanks for the link, but, well... that still doesn't answer how I can
    page something that can't be a part of the sql statement.

    I DO know how to page it, IF the constraints are added inside the sql
    statement. My problem is that the contraint I have (the memo field)
    can't be searched using SQL.

    If you take a look at the code I posted earlier, the memo search
    filtering only began inside the "DO WHILE not rs.EOF" statement. When
    this happens, even tho the recordset says it has 8 results, the actual
    result might be less because of the memo filtering done afterwards.

    BTW, I forgot to mention that I'm using Access 2000 for my db backend.
    Appreciate any tips or links you may have.
    Hate Spam Guest

  4. #3

    Default Re: ASP Paging on a searched memo field

    Hate Spam wrote:
    >
    > I need advice on how to integrate the paging capbility to my search
    > script. The program I built requires me to make word search on several
    > db fields including one that's a memo type field, which doesn't work
    > with just a LIKE statement.
    > I was doing OK up till the part where I needed to page the results.
    > Here the code that I used (note that the code doesn't have paging
    > yet):
    >
    > ===== start code =====
    >
    > ' generate sql for search
    > if request.form("btnSubmit") = "Search" then
    > strTitle = request.form("fldTitle") 'subject field
    > strContent = lcase(request.form("fldContent")) 'news content field
    >
    > 'generate sql
    > strSqlsearch = "select * from News "
    > if strTitle <> "" then
    > strSqlsearch = strSqlsearch & "where Subject like '%" &
    > strTitle & "%' "
    > else
    > strSqlsearch = strSqlsearch & "and Subject like '%" &
    > strTitle & "%' "
    > end if
    > strSqlsearch = strSqlsearch & "order by id desc"
    >
    > ' run sql search
    > SQLstatement = strSqlsearch
    > set rs = conn.Execute(SQLstatement)
    >
    > ' get ready to display
    > if rs.eof then
    > ' display not found msg
    > response.write "<p>No info matches your search.</p>"
    > else
    > ' write out results
    > do while not rs.eof
    > ' chg memo field to string
    > strContentrs = lcase(rs("Content"))
    > ' check if contains keyword for content
    > if instr(strContentrs, strContent) > 0 then
    > response.write "some stuff to be written"
    > end if
    > rs.movenext
    > loop
    > end if
    > end if
    >
    > ===== end code =====
    >
    > Again, could someone advise me how to go about paging this?
    Since you want a page that displays N records at a time, add a counter
    that exits the loop after N records have displayed.

    When first executed the ASP page displays N records fitting the criteria
    and then exits. Prior to exiting, save the id value (we'll call it
    PreviousID) of the last displayed record in a Session variable, a hidden
    <FORM> field, or a querystring variable. On subsequent page executions
    (all executions except the first) retrieve PreviousID and add the
    following criteria to the SQL statement:
    WHERE ID < PreviousID

    This ensures that each page after the first picks up where the previous
    one left off.

    Also add code to handle end of data: when you display the last record
    (rs.EOF is true) set the PreviousID to an appropriate value (e.g. 0, -1,
    "").

    This will work because you have ordered your information by ID. If you
    change the retrieval order you will have to correspondingly change the
    "pointer" that you are saving between pages.

    Good Luck,
    Michael D. Kersey
    Michael D. Kersey Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139