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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting question... 1

Status
Not open for further replies.

Delameko

Programmer
Oct 14, 2003
37
GB
I'm not an ASP developer, but I've been given a (seemingly easy) task to complete.

The code below is going to be put into an iframe. Its 'what happened on this day' type thing, showing birthdays, deaths, etc. So I need to only show the records with todays date, and only show 3-4 entries at a time.

What is the best way to go about doing this?


Code:
<%
While Not Recordset1.EOF
%>

<p><b><%=(Recordset1.Fields.Item("eventdate").Value)%>/<%=(Recordset1.Fields.Item("eventmonth").Value)%>/<%=(Recordset1.Fields.Item("eventyear").Value)%>:</b>&nbsp;<%=(Recordset1.Fields.Item("eventtitle").Value)%><br>
<%=(Recordset1.Fields.Item("eventprecis").Value)%><br>
(<%=(Recordset1.Fields.Item("eventcategory").Value)%>)<br>
<%=(Recordset1.Fields.Item("eventdetail").Value)%>


<%
  Recordset1.MoveNext
Wend
%>
 
What is the best way to go about doing this?
Look into paging recordsets. good simple example: ADO Recordset Paging in ASP


For what you have there and in saying you are new to ASP scripting, take a look at your code
Code:
<%
While Not Recordset1.EOF
%>

<p><b><%=(Recordset1.Fields.Item("eventdate").Value)%>/<%=(Recordset1.Fields.Item("eventmonth").Value)%>/<%=(Recordset1.Fields.Item("eventyear").Value)%>:</b>&nbsp;<%=(Recordset1.Fields.Item("eventtitle").Value)%><br>
<%=(Recordset1.Fields.Item("eventprecis").Value)%><br>
(<%=(Recordset1.Fields.Item("eventcategory").Value)%>)<br>
<%=(Recordset1.Fields.Item("eventdetail").Value)%>


<%
  Recordset1.MoveNext
Wend
%>

Now take a look at this
Code:
Do While NOT Recordset1.EOF
	Response.Write "<p><b>" & Recordset("eventdate") & "/" & Recordset("eventmonth") & "/" & Recordset("eventyear")
	Response.Write "<br>" & Recordset("eventprecis") & "<br>"
	Response.Write "<br>(" & Recordset("eventcategory") & ")<br>"
	Response.Write "<br>" & Recordset("eventdetail") & "<br>"
Recordset1.MoveNext
Loop

First take into account maintainability. Second take into account performance without even thinking of how ASP will interpret all those <% %> and looping structure used but seemingly common sense in a way. You limit responses and you limit basically messy code that can be syntax hell when it comes to finding problems in it. To further it you can take all of the responses out but one in reality but you loose ease of maintaining it again so it is good practice to split it up a bit.


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
:) hop[e it helps. Let us know if you run into any walls


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top