Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying search results in bold

Status
Not open for further replies.

Craigieboy

Programmer
May 25, 2001
71
GB
I have a simple SQL database with an ASP front end used for querying the database - one page for entering in your search criteria and another page for displaying the results in a table. Fairly simple, right?

What I would like to do is display my search criteria in bold within my results table. The idea is to make it easier on the eye for the user to see their results in amongst a whole heap of other text.

Is there any way I can perhaps run a regular expression over the page which will reformat the search text only in bold? I really want to keep this as simple as possible if I can.

With thanks in advance,
Craig ~~ The attention span of a computer is only as long as it's electrical cord. ~~
 
Presumably you are using response.write to output your search results.

If MyText is the output and MyQuery is the query Replace response.write(MyText) with:

response.write(replace(MyText,MyQuery,&quot;<b>&quot; & MyQuery & &quot;</b>&quot;))
 
I am using Response.Write but the way that I am building my table is by using the 'GetString' method as described in the Wrox ASP Databases book. I know there are probably different (and perhaps better) ways of displaying a table, however at this point in time this is the only way I know how :-(

My line of code is...

Response.Write inetRS.GetString(,,&quot;<td bgcolor=#EFF3F6 valign='top' align='left'>&quot;,&quot;</td></tr><tr bgcolor=#EFF3F6 valign='top' align='left'><td>&quot;)

Can this line be adapted in anyway or is it looking like more hassle than it's worth?

Thanks for your help iowtech - can you help any further?

Kind regards,
Craig
~~~~ The attention span of a computer is only as long as it's electrical cord. ~~~~
 
I can't think of a way of achieving what you want using the GetString method, mabye someone else can.

Its your call whether this is worth the hassle. Personally I think it is from a readability point of view.

Try the code below. Please excuse any bugs as I haven't tested it, just written on the fly. Let me know how you get on! :)

while inetRS.eof = false
response.write(&quot;<tr bgcolor=#EFF3F6 valign='top' align='left'>&quot;
for a = 0 to inetRS.fields.count - 1
response.write(&quot;<td bgcolor=#EFF3F6 valign='top' align='left'>&quot; & replace(inetRS.fields(a).value,MyQuery,&quot;<b>&quot; & MyQuery & &quot;</b>&quot;) & &quot;</td>&quot;)
next
response.write(&quot;</tr>&quot;)
inetRS.movenext
wend
 
Hi iowtech

Thanks very much for your help with my query and for your code. There were a few little bugs, but not to worry as I have taken the bulk of your code and have now resolved all my current issues.

Thanks again for your help - much appreciated.

For your info here is my working code...
Code:
Dim field_val

While inetRS.eof = False

Response.Write(&quot;<tr bgcolor=#EFF3F6 valign='top' align='left'>&quot;)

For a = 0 to inetRS.fields.count - 1

field_val = inetRS.fields(a).value

If not field_val = &quot;&quot; or not isNull(field_val) Then

Response.Write(&quot;<td bgcolor=#EFF3F6 valign='top' align='left'>&quot; & _
Replace(field_val,estate_details,&quot;<b>&quot; & ucase(estate_details) & &quot;</b>&quot;,1,-1,vbTextCompare) & &quot;</td>&quot;)

Else

Response.Write &quot;<td bgcolor=#EFF3F6 valign='top' align='left'></td>&quot;

End If

Next

Response.Write(&quot;</tr>&quot;)

inetRS.movenext

Wend

Kind regards,
Craig :)
 
Sorry about the bugs! Glad to be of assistance. Sometimes all you need is a shove in the right direction and it all comes together.

Thanks for posting you final code. Looks pretty good!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top