views:

54

answers:

3

Hi there,

I have a single Classic ASP page that I wish to display a search form and the associated results.

When a user first comes to this page, I want to display a search form and the 10 latest properties. If a user decides to use the search form to retrieve more relevant properties, then i want the default 10 latest properties to be replaced with the users' paged search results.

I was wondering if this is possible/practical within the confines of one page and if so, does anyone have any hints on how i could best achieve this?

This is my preliminary code for such a page; http://gist.github.com/188770

Once again, i'm currently having to patch an existing ASP site until I can redevelop it in something more modern like PHP.

Thank you for any help offered.

Neil.

+1  A: 

It's certainly very possible and practical. Typically the solution is to postback to yourself and have code in the page that detects if you arrived there from a post or a get. Get meant show the 10 latest properties, post means you do a search and show the results.

if (Request.ServerVariables("REQUEST_METHOD") = "POST") then

   ' arrived via post, get form values and do search
else

   ' arrived via get, show last 10 results

end if
Nissan Fan
Hi there, thank you for the quick response. I have updated my 'gist' code with how I understand your solution;http://gist.github.com/188770Does this look about right? :)
No, you have SQL injection problems. Use parameterized queries...
RedFilter
You also need a an ORDER BY clause on the TOP 10 query.
AnthonyWJones
A: 

@OrbMan: I have updated my code with (what I think is the way to set parametized queries. Would you be able to take a quick look for me?

http://gist.github.com/188770

Thank you very much.

Neil Bradley
Please add this to the question, as this clearly isn't a answer.
svinto
Hi, I wanted to but the 'add comment' link doesn't display underneath the other reponses for me to add my comment. :(
Neil Bradley
A: 

You probably want to display what the user searched for in the form when you display the result:

<label>Street: <input type="text" name="searchStreet" value="<%=Server.HtmlEncode(Request("searchStreet") & "") %>" /></label>

Adding a empty string is for casting to string to not give an error when the key wasn't found, eg. on first visit.

If you want to you can make the loop prettier:

do until myRecordSet.EOF
%>
<div class='result'>")
  <dl><%=myRecordSet("ContentTitle")%><dl>
  <dt><%=myRecordSet("ContentStreet")%><dt>
  <dt><%=myRecordSet("ContentTown")%><dt>
  <dt><%=myRecordSet("ContentPostcode")%><dt>
</div><%
myRecordSet.MoveNext
loop

You probably want to Server.HtmlEncode there as well...

(ps ASP is actually one year younger than PHP... if you want something modern you might want to look at python, ruby or asp.net mvc before PHP, as it's easier to write bad code in PHP than in any of those. ds)

svinto
Good P.S. :) Theres nothing wrong with good old ASP if its written well.
Pete Duncanson