
|
ASP can be used to display information directly from a database residing on the server, without the database naming conventions being available to the viewer. It also allows ease and speed in accessing the database information. See also Dreamweaver/UltraDev Notes
Note that the database information and other information pertaining to the table shown is not shown in the final html code available in a browser. The ASP code below connects to a MySQL database, and produces a standard table data display.
<%
' this code opens the database
connect_string = "Driver={Mysql}; Server=localhost;
Database=domainname_com; UID=username; PWD=password"
set dbConn = server.createObject("ADODB.connection")
dbConn.open connect_string
' this code retrieves the data
mySQL="select * from asptest"
set rstemp=dbConn.execute(mySQL)
' this code detects if data is empty
If rstemp.eof then
response.write "No records matched
"
response.write mySQL & "
So cannot make table..."
connection.close
set connection=nothing
response.end
end if
%>
<%
' This code puts fieldnames into column headings
response.write "<tr>"
for each whatever in rstemp.fields
response.write "<td>" & whatever.name & "</TD>"
next
response.write "</tr>"
' Now lets grab all the records
DO UNTIL rstemp.eof
' put fields into variables
Name=rstemp("name")
City=rstemp("city")
State=rstemp("state")
Email=rstemp("email")
Phone=rstemp("phone")
Name=rstemp("name")' write the fields to browser
cellstart="<td align=""top"">"
response.write "<tr>"
response.write cellstart & Name & "</td>"
response.write cellstart & City & "</td>"
response.write cellstart & State & "</td>"
response.write cellstart & Email & "</td>"
response.write cellstart & Phone & "</td>"
response.write "</tr>"
rstemp.movenext
LOOP
%>
<%
' Now close and dispose of resourcesrstemp.close
set rstemp=nothing
dbConn.close
set dbConn=nothing
%>
From here you can easily modify the SELECT statement to look for specific results, much as you would from a Search box. So this modified SELECT statement:
mySQL="select * from asptest where phone LIKE '555%'"
produces a table display for only 555 numbers.
Dreamweaver/UltraDev Notes
Macromedia Dreamweaver-UltraDev has built-in tools to help you develop database connections using ASP. There are a couple of good sites devoted to UltraDev and MySQL that provide step by step techniques which will work on our servers for connecting these two:
|
|