How do I limit the amout of records returned by a query statement? For example, How would I pull only the first ten records that match a certain criteria?
----------------------- try this as an example also ====================
SEARCHTEXT is a value request from a form. ill explain the rest after
<% Dim DATAPATH DATPATH = "c:\path\to\database" 'path to your database
Set rsRECORDSET = Server.CreateObject("ADODB.Recordset") Set DATABASE = Server.CreateObject("ADODB.Connection") DATABASE.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DATA_PATH & ";
SQL = "SELECT * FROM TABLE_NAME WHERE FIELD_NAME LIKE '%" & SEARCHTEXT & "%' ORDER BY FIELD_NAME ASC;"
rsRECORDSET.Open SQL, DATABASE
Dim MAXRECORDS MAXRECORDS = 10 ' define the amount of records you want to show
Dim COUNTER COUNTER = 1
Do while NOT rsRECORDSET.EOF AND COUNTER <= MAXRECORDS 'Now write out the html in the way you want to display your info. Example below %> Name: <%= rsRECORDSET("FIELD_NAME_ONE") Phone: <%= rsRECORDSET("FIELD_NAME_TWO") <br><br> <% COUNTER = COUNTER + 1 rsRECORDSET.Movenext loop
rsRECORDSET.close Set rsRECORDSET = NOTHING DATABASE.close SET DATABASE = NOTHING %>
The SQL statement simply searchs in TABLE_NAME where the FIELD_NAME is LIKE the SEARCHTEXT. Then it ORDERs them by FIELD_NAME alphabet/// or Numerically.
The rest yout should understand. The other method might be easier, but hey
Regards - Spoon
Begineer? Need help installing the forums? - www.aslickpage.com/snitz_help.html