Click to See Complete Forum and Search --> : Loading table from database


MarkGG
06-21-2005, 09:06 AM
I have a database with four tables, Main(has just ID_NUM, NAME, TYPE), Facility, People, Town.

I want to make it so that when someone accesses the page it would load a list of all the entries in the Main table, so all the ID_NUMs, NAMEs, TYPEs. In addition I would like to make the NAMEs a link so that they may be clicked and it would take you to another page, but that is a bit more complicated. So, how do I get my Main table to load into an HTML table?

I have this but it isn't working

<HTML>

<%
Dim con,sql,constring
Set con = Server.CreateObject("ADODB.Connection")
%>


<!-- #include file="dbConnect.ssi" -->

<%
sql = "Select * from main order by ID_NUM"
'I open my connection
con.Open dbConnect
'I execcute
con.Execute(sql)
%>


<body bgcolor=#6699CC link="blue" vlink="blue" alink="blue">
<center><font size="4" color="black"><b>Edit Current Entries</b></font></center>
<hr width = 50% size =4>
<br>
</center>
From this page you may edit entires which are currently already in the database. This is a complete list of the database contents. Just click on one of the names and you will be taken to a page where you may edit the values.
<table border = "2" bgcolor="white">
<%
do until con.eof
response.write("<tr>" & "<td>" & con.fields("ID_NUM") & "</td>" & "<td>" & con.fields("NAME") & "</td>" & "<td>" & con.fields("TYPE") & "</td>" & "</tr>")>")
con.movenext
loop
con.close
%>

</table>
</body>
</HTML>

lmf232s
06-21-2005, 10:58 AM
i did not really study your code but it looks like you have it.
You just loop the recordset and create you html. You could do it server side,
kind of like you had it or you could do it below where you bounce back from
asp to html. Does not matter one way of the other, you get the color coding
if you program in a editor, which may be nice.


<%
<table class=table width=100%>
SQL = "SELECT FIELDS FROM TABLE"
objRS.Open SQL, objConn, 3, 3
Do While Not objRS.EOF
%>
<tr>
<td><%=objRS("ID")%></td>
<td><a href="NewPage.asp?ID=<%=objRS("ID")%>"><%=objRS("ID")%></td>
<td><%=objRS("NAME")%></td>
</tr>
<%
objRS.MoveNext
Loop
objRS.Close
%>
</table>

MarkGG
06-21-2005, 01:40 PM
Worked like a charm, thanks

lmf232s
06-21-2005, 01:43 PM
no problem, glad to help