Udtræk og søgning i database
Jeg her følgende kode der viser 4 dropdown menuer som bruges til at søge i en Access database og kun vise det der matcher.Jeg vil nu gerne lave om så boligtypen bliver hentet fra databasen, (tabellen boligtyper) men hvordan?
<% mode = request("mode")
boligtype = request("boligtype")
region = request("region")
sovepladser = request("sovepladser")
vaerelser = request("vaerelser")
if mode = "search" then
if boligtype <> "ALLE" then
boligtypeSQL = "boligtype = '" & boligtype & "' and "
whereSQL = true
end if
if region <> "ALLE" then
regionSQL = "region = '" & region & "' and "
whereSQL = true
end if
if sovepladser <> "ALLE" then
sovepladserSQL = "sovepladser = '" & sovepladser & "' and "
whereSQL = true
end if
if vaerelser <> "ALLE" then
vaerelserSQL = "vaerelser = '" & vaerelser & "' and "
whereSQL = true
end if
strSQL = "SELECT * FROM boliger"
if whereSQL then strSQL = strSQL & " WHERE "
strSQL = strSQL & boligtypeSQL & regionSQL & sovepladserSQL & vaerelserSQL
if right(strSQL,4) = "and " then strSQL = left(strSQL,len(strSQL)-5)
strSQL = strSQL & " ORDER BY by"
end if %>
<form method="POST" action="default.asp?page=soegbolig&mode=search">
<table border="0" width="100%" cellspacing="0" cellpadding="5">
<tr>
<td width="16%">Boligtype:</td>
<td width="84%"><select size="1" name="boligtype" class="boxInput">
<option value="ALLE">ALLE</option>
<option <% if boligtype = "Sommerhus" then %>selected<% end if %>>Sommerhus</option>
<option <% if boligtype = "Lejlighed" then %>selected<% end if %>>Lejlighed</option>
<option <% if boligtype = "Båd" then %>selected<% end if %>>Båd</option>
<option <% if boligtype = "Campingvogn" then %>selected<% end if %>>Campingvogn</option>
</select></td>
</tr>
<tr>
<td width="16%">Region:</td>
<td width="84%"><select size="1" name="region" class="boxInput">
<option value="ALLE">ALLE</option>
<option <% if region = "Nord Jylland" then %>selected<% end if %>>Nord Jylland</option>
<option <% if region = "Midt Jylland" then %>selected<% end if %>>Midt Jylland</option>
<option <% if region = "Sønder Jylland" then %>selected<% end if %>>Sønder Jylland</option>
<option <% if region = "Fyn" then %>selected<% end if %>>Fyn</option>
<option <% if region = "Nord Sjælland" then %>selected<% end if %>>Nord Sjælland</option>
<option <% if region = "Syd Sjælland" then %>selected<% end if %>>Syd Sjælland</option>
<option <% if region = "Lolland/Falster" then %>selected<% end if %>>Lolland/Falster</option>
<option <% if region = "Bornholm" then %>selected<% end if %>>Bornholm</option>
</select></td>
</tr>
<tr>
<td width="16%">Sovepladser:</td>
<td width="84%"><select size="1" name="sovepladser" class="boxInput">
<option value="ALLE">ALLE</option>
<option <% if sovepladser = "1" then %>selected<% end if %>>1</option>
<option <% if sovepladser = "2" then %>selected<% end if %>>2</option>
<option <% if sovepladser = "3" then %>selected<% end if %>>3</option>
<option <% if sovepladser = "4" then %>selected<% end if %>>4</option>
<option <% if sovepladser = "5" then %>selected<% end if %>>5</option>
<option <% if sovepladser = "6" then %>selected<% end if %>>6</option>
<option <% if sovepladser = "7" then %>selected<% end if %>>7</option>
<option <% if sovepladser = "8" then %>selected<% end if %>>8</option>
<option <% if sovepladser = "9" then %>selected<% end if %>>9</option>
<option <% if sovepladser = "10" then %>selected<% end if %>>10</option>
<option <% if sovepladser = "11" then %>selected<% end if %>>11</option>
<option <% if sovepladser = "12" then %>selected<% end if %>>12</option>
<option <% if sovepladser = "Flere end 12" then %>selected<% end if %>>Flere end 12</option>
</select></td>
</tr>
<tr>
<td width="16%">Værelser:</td>
<td width="84%"><select size="1" name="vaerelser" class="boxInput">
<option value="ALLE">ALLE</option>
<option <% if vaerelser = "1-5" then %>selected<% end if %>>1-5</option>
<option <% if vaerelser = "6 eller der over" then %>selected<% end if %>>6 eller der over</option>
</select></td>
</tr>
</table>
<p><input type="submit" value="SØG" name="B1" class="boxSubmit"></p>
</form>
<% if mode = "search" then %>
<table width="100%" cellspacing="0" cellpadding="5">
<tr>
<td width="80%" style="border-bottom:solid 1px #CCCCCC"><%=rs("postnr")%> - <%=rs("by")%><br><br>
<%=rs("sovepladser")%> sovepladser<br>
<p><A HREF="default.asp?page=visbolig&ID=<%=rs("ID")%>" style="color:#0000FF">Læs mere...</A></p></td>
<td width="20%" align="center" style="border-bottom:solid 1px #CCCCCC">
<% Set fso = CreateObject("Scripting.FileSystemObject")
path = Server.MapPath("/data/images/" & rs("ID") & "-1.jpg")
if fso.FileExists(path) then %><A HREF="default.asp?page=visbolig&ID=<%=rs("ID")%>">
<img src="/data/images/<%=rs("ID")%>-1.jpg" alt="" width="140" height="100" border="0"></A>
<% else %>
intet billede
<% end if %>
</td>
</tr>
<% rs.MoveNext
loop
rs.Close
Set rs = Nothing %>
</table>
<% end if %>
