Use this example to see the core idea, then work through the complete steps below. Code snippets are Classic ASP / VBScript or SQL Server T-SQL as labelled, not PHP.
VBScript example
Set rs = cn.Execute("SELECT id, name FROM dbo.student ORDER BY id")
Do While Not rs.EOF
Response.Write Server.HTMLEncode(CStr(rs("name"))) & "<br>"
rs.MoveNext
Loop
rs.CloseThis Classic ASP fragment requires an open SQL Server ADO connection cn. The original complete example below includes connection and cleanup steps.
Displaying SQL Server rows follows the same ADO Recordset pattern as Access: open a connection, execute a SELECT statement, loop until EOF, encode the values for HTML and release database objects.
<%@ Language="VBScript" %>
<% Option Explicit %>
<!-- #include virtual="/adovbs.inc" -->
<!-- #include virtual="/conn.asp" -->
<%
Dim conn, rs
Set conn = Server.CreateObject("ADODB.Connection")
conn.Mode = adModeRead
conn.ConnectionString = aConnectionString
conn.Open
Set rs = conn.Execute("SELECT issue_dt FROM dt ORDER BY issue_dt")
Do While Not rs.EOF
Response.Write Server.HTMLEncode(CStr(rs("issue_dt"))) & "<br>"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
%>
Connection.Execute() is convenient for a fixed read-only query. If the query contains visitor-controlled values, create an ADODB.Command and add parameters instead.
Use a fixed SQL query for simple listing pages. If the query filters by a visitor value, use a parameterized ADODB.Command and validate its input.
Encode dynamic field values with Server.HTMLEncode(), balance opening and closing table tags, and handle empty results before showing column headings or rows.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.