PDA

View Full Version : How display the results


luigicannavaro
11-07-2008, 12:40 PM
Dear friends,


I have the following ASP script to display selected data. Well, but I would like to display selected data within parameters:

I want to show only 100 characters before and 100 characters after the filter keyword or keywords from a memofield (named contents). Taking into account the boundaries of that 100 characters. 'Contents' is a memofield.

My ASP script:
____________


<html>
<body>

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"

Dim strkeyword
Strkeyword= Request.Querystring("look_for")

set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT contents FROM Customers
WHERE CompanyName LIKE '"" %Strkeyword% "' "
rs.Open sql, conn
%>

' contents it is a memofield

<table border="1" width="100%">
<tr>
<%for each x in rs.Fields
response.write " 100 characters before strkeyword "
response.write strkeyword
response.write " 100 characters after strkeyword "

next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close%>
</table>

</body>
</html>

_____________________________________________


Thank you so much

Luigi
______
______

luigicannavaro
11-13-2008, 09:38 AM
Ok. What I want to say may be saw in these examples. It have not an easy solution. Why? The boundaries of that text.



Taking the text:


Federal bank regulators have rejected a request by banks and consumer advocates for a program to let lenders forgive huge portions of credit card debt. The Office of the Comptroller of the Currency rejected the request for a special program that would allow as much as 40 percent of credit card debt to be forgiven for consumers who don't qualify for existing repayment plans.

Example 1: Looking for the word: Currency

We will get the following output:

program to let lenders forgive huge portions of credit card debt. The Office of the Comptroller of the Currency rejected the request for a special program that would allow as much as 40 percent of credit card debt


Example 2: Looking for the word existing

We will get the following output:

would allow as much as 40 percent of credit card debt to be forgiven for consumers who don't qualify for existing repayment plans

Example 3: Looking for the word request

Federal bank regulators have rejected a request by banks and consumer advocates for a program to let lenders forgive huge portions of credit card debt.


Example 4: Looking for the word credit

Do you will have two outputs:

rejected a request by banks and consumer advocates for a program to let lenders forgive huge portions of credit card debt. The Office of the Comptroller of the Currency rejected the request for a special program

and

of the Currency rejected the request for a special program that would allow as much as 40 percent of credit card debt to be forgiven for consumers who don't qualify for existing repayment plans.
I will be grateful for any feedback.

Luigi

Spudhead
11-13-2008, 03:59 PM
RegExp is definitely the way forward.

How about this:


<%
haystack = "Federal bank regulators have rejected a request by banks and consumer advocates for a program to let lenders forgive huge portions, of credit card debt. The Office of the Comptroller of the Currency rejected the request for a special program that would allow as much as 40 percent of credit card debt to be forgiven for consumers who don't qualify for existing repayment plans."

needle = "credit"

dim oRE
set oRE = New RegExp
oRE.IgnoreCase = True
oRE.Global = True
oRE.Pattern = "(\w+\.?,?\s){0,10}"& needle &" (\w+\.?,?\s){0,10}"
Set myMatches = oRE.Execute(haystack)
For Each myMatch in myMatches
response.write(replace(myMatch.Value, needle, "<b>" & needle & "</b>") & "<br/>")
Next
set oRE = nothing

%>


Rather than grabbing the 100 characters either side - which might split words and isn't going to look too pretty - it'll match 10 words either side.

My RegExp isn't too hot, so it probably needs refining. Currently it'll match a word as being a bunch of word-characters, optionally followed by a full stop or a comma, followed by a space. I had a go with \b but couldn't get it to match :confused:

luigicannavaro
11-14-2008, 01:50 PM
SpudHead,

Thank you so much. Your script it is enough for my needs, evidently I will refining the RegExp special characters (a lot of hours). However it is working fine.

Thank you again.

Luigi:thumbsup: