Using Select Statement With A Loop.
In this example we are selecting all records and
showing them all.
The SQL statement is the key and by changing that you can limit the results however you
want. This is just an example to get you started.
Don't be afraid to mix a
little creative HTML before, during, and after the loop. Thats how dynamic tables are
created.
<%
' declaring variables
' not neccesary but a good habit
Dim DataConn
Dim CmdSimpleSelect
Dim MYSQL
Set DataConn = Server.CreateObject("ADODB.Connection")
Set CmdSimpleSelect = Server.CreateObject("ADODB.Recordset")
' The line below shows how to use a system DSN instead of a DNS-LESS connection
' DataConn.Open "DSN=System_DSN_Name"
DataConn.Open "DBQ=" & Server.Mappath("../_database/database.mdb")
& ";Driver={Microsoft Access Driver (*.mdb)};"
MYSQL = "SELECT ID, NAME, EMAIL, MESSAGE FROM some_table"
CmdSimpleSelect.Open MYSQL, DataConn
' the following code causes the select Statement to start looping through the records
While Not CmdSimpleSelect.EOF
%>
<%=
CmdSimpleSelect("ID") %><br>
<%= CmdSimpleSelect("NAME") %><br>
<%= CmdSimpleSelect("MESSAGE") %><br>
<%= CmdSimpleSelect("EMAIL") %><br>
<hr>
<%
' the following code ends the loop
CmdSimpleSelect.MoveNext
Wend
' closing objects and setting them to nothing
' not neccesary but a good habit
CmdSimpleSelect.Close
Set CmdSimpleSelect = Nothing
DataConn.Close
Set DataConn = Nothing
%>
|