PDA

View Full Version : get values from db...


Mhtml
09-20-2002, 09:12 AM
ok, I can do this with a text file but with ADO I have no idea...

I need to get the values LinkUrl LinkName and LinkDesc from a database and put them together like this:

"<tr><td>" & "<a href=" & LinkUrl & ">" & LinkName & "</a>" & "</td><td align=right>" & LinkDesc & "</td></tr>

it will need to loop until all values have been outputed into there own <tr>s'

also this is probably easier to answer than the above, but does eof = end of fields?

raf
09-20-2002, 09:39 AM
eof = end of file (bof = beginning of file) (file is the array and the eof is the last row in that area)

I think your question comes down to : how to get data from recordset, and use that in a dynamicaly build table with links to records.
The principle is simple : you refere the record in the recordset using rsNAMERECORDSET.Fields("NAMEVARIABLE")

the code below creates a table and loops through the recordset (the aray) to populate the table. each record from the recordset comes in a new row with alternated backgrounds.

In the last colom, you get two links for each record. one to start an order fo that client and one to look at the clients details

The way that the url or created is what interests you. In my example, the link alwau point to the same page, buth i pass the clientsID along.

In your case it will be something easier.

[code]

response.write("<a href=" & rsLinks.Fields("linkUrl") & ">" & rsLinks.Fields("linkName") & "</a></td><td align=right>" & rsLinks.Fields("linkDesc") & "</td>")

[/code ]
where rsLinks is the name of the recordset


example code
[code]


if rsOrders.EOF=true then
response.write("<font color='red'><b>Geen klant gevonden.</b></font><br><br>")
response.write("<font color='red'>Zoektips:<br>&nbsp;&nbsp;- Controleer de ingevoerde gegevens<br>&nbsp;&nbsp;- Probeer met één of meerdere van de andere criteria te zoeken.<br>&nbsp;&nbsp;- Gebruik maar één zoekterm per criterium (zoekterm = naam of deel van een naam)</font>")
response.write("<br><br><a href='javascript:history.back();'>Teruggaan</a>")

else

dim rij
rij = "0"
response.write("<b>Zoekresultaat:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:history.back();'>Nieuwe selectie</a><br><br>")
response.write("<table border='0' cellpadding='5' cellspacing='0' width='95%'>")
response.write("<tr bgcolor='#c6d8df'>")
response.write("<td><b>Naam(contactpersoon)</b></td><td><b>Firmanaam</b></td><td align='center'><b>Acties</b></td>")
do while rsKlanten.EOF=false if rij MOD 2 = 0 then
response.write("<tr bgcolor='#ddf1f9'>")
else
response.write("<tr bgcolor='#e0ebeb'>")
end if
response.write("<td>" &server.HTMLEncode (rsKlanten.Fields("naam")) &"&nbsp;"& server.HTMLEncode (rsKlanten.Fields("voornaam")) &"</td>")
response.write("<td>" &server.HTMLEncode (rsKlanten.Fields("firmanaam")) &"</td>")
response.write("<td align='right'><a href=order_klant.asp?klantnummer=" &rsKlanten.Fields("klantnummer") & ">Order invoeren </a><br>")
response.write("<a href=gegevens_klant_bekijken.asp?klantnummer=" &rsKlanten.Fields("klantnummer") & ">Klantengegevens bekijken/aanpassen </a></td>")
response.write("</tr>")
rij = rij+1
rsKlanten.MoveNext
loop
response.write("</table>")
end if

[/code ]

Mhtml
09-20-2002, 09:41 AM
I found this at www.liquidrage.com and modified it:

<%

'This is the code used to make a connection to our database
Set ConnSQL = Server.CreateObject("ADODB.Connection")
path = Server.MapPath("databases/odyssey.mdb")
ConnSQL.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & path


'Building our SQL string that we'll execute a few lines down
sqlEasyQuery = "SELECT LinkName, LinkUrl, LinkDesc FROM Links"

'The Recordset is another ADO Object
Set RS = server.CreateObject("adodb.recordset")


'Executing our SQL string and placing it into our RecordSet
'Notice we use the "Execute" Method of the Connection object
'not the Recordset object. The Recordset object gets set to
'what the Connection Object "Execute" method returns.
Set RS = ConnSQL.execute(sqlEasyQuery)

'At this point we have a record set named "RS". We're going to
'do a quick test to make sure the record set has data and set
'up some HTML to handle it either way

if RS.eof then
'if we get in here our recordset returned empty. Of course
'considering the table exists, has data, and we have no where
'clause in our SQL we should never hit this point of the code
%>
<div align=center>
<h3>
Sorry, no links found.
</h3>
</div>
<%
else
'If we're in this section of the code, we found some data to display
'The table we ran the query on has 4 fields but we only asked for 2 of them.
' We'll loop through our record set displaying each field.
%>

<% 'Here is where we actually go through the record set.
'We loop through it writing some HTML as we go
While not RS.EOF
Response.Write("<tr><td><a href=" & Rs.Fields("linkUrl") & ">" & Rs.Fields("LinkName"))
Response.Write("</td><td align=right>" & RS.Fields("LinkDesc") & "</td></tr>")
RS.Movenext
Wend
%>
</table>
<%
end if
ConnSQL.Close
Set ConnSQL = nothing
Set RS = nothing
%>