i have a question about writing a many to many table
ne examples would be welcome
a user can choose a car and then choose accessories they would like for that car.
at the moment my page loops through the accessories table and lists all products.
at the end of each row is a yes/no dropdown to select requirement.
the options come from a table with yes having the id 1.
when the form is posted i would like all accessories with the yes combo value of 1 to have the id of the accessory and the id of the car written to the link table (below)
tbl_car
----------
carid
make
tbl_acclink
------------
acclinkid
carid
accid
tbl_acc
------------
accid
accessory
am i making sense?, my code so far is below
also i dont want to use a mutiple choice list box
as it looks naff
ne ideas welcome
<%
strsql = "SELECT * FROM `tbl_acc` ORDER BY tbl_acc.accdesc"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.cursorlocation = 3
rs.Open strsql, conn, 1, 2
%>
</p>
<table width="357" height="28" border="0" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<%
Do While (Not rs.Eof)
' Set row color
bgcolor = "#FFFFFF"
%>
<%
' Display alternate color for rows
If recCount Mod 2 <> 0 Then
bgcolor = "#F5F5F5"
End If
%>
<%
' Load Key for record
key = rs("accid")
If VarType(key) = 18 Or VarType(key) = 19 Then ' adUnsignedSmallInt/adUnsignedInt
If IsNull(key) Then
key = Null
Else
key = CInt(key)
End If
End If
x_accid = rs("accid")
x_accdesc = rs("accdesc")
x_acccost = rs("acccost")
%>
<tr bgcolor="#F5F5F5">
<td width="219" height="26"><span class="aspmaker"> <font size="1">
<font size="2"> <font color="#666666">
<%
Response.Write x_accdesc
Response.Write x_accid
%>
</font></font></font></span><font color="#666666" size="2"> </font></td>
<td width="67"><div align="center"><span class="aspmaker"><font color="#666666" size="2">
<strong>
<%
Response.Write "£" & x_acccost
%>
</strong> </font> </span></div></td>
<td width="43"><span class="aspmaker">
<%
x_stockaccList = "<select name='x_stockacc'><option value=''>Select</OPTION>"
sqlwrk = "SELECT `ynid`, `yn` FROM `tbl_yn`"
Set rswrk = Server.CreateObject("ADODB.Recordset")
rswrk.Open sqlwrk, conn, 1, 2
If Not rswrk.Eof Then
datawrk = rswrk.GetRows
rowswrk = UBound(datawrk, 2)
For rowcntwrk = 0 To rowswrk
x_stockaccList = x_stockaccList & "<option value='" & datawrk(0, rowcntwrk) & "'"
If CStr(datawrk(0, rowcntwrk)&"") = CStr(x_stockacc&"") Then
x_stockaccList = x_stockaccList & " selected"
End If
x_stockaccList = x_stockaccList & ">" & datawrk(1, rowcntwrk) & "</option>"
Next
End If
rswrk.Close
Set rswrk = Nothing
x_stockaccList = x_stockaccList & "</select>"
Response.Write x_stockaccList
%>
</span></td>
</tr>
<%
rs.MoveNext
Loop
%>
</table>
ne examples would be welcome
a user can choose a car and then choose accessories they would like for that car.
at the moment my page loops through the accessories table and lists all products.
at the end of each row is a yes/no dropdown to select requirement.
the options come from a table with yes having the id 1.
when the form is posted i would like all accessories with the yes combo value of 1 to have the id of the accessory and the id of the car written to the link table (below)
tbl_car
----------
carid
make
tbl_acclink
------------
acclinkid
carid
accid
tbl_acc
------------
accid
accessory
am i making sense?, my code so far is below
also i dont want to use a mutiple choice list box
as it looks naff
ne ideas welcome
<%
strsql = "SELECT * FROM `tbl_acc` ORDER BY tbl_acc.accdesc"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.cursorlocation = 3
rs.Open strsql, conn, 1, 2
%>
</p>
<table width="357" height="28" border="0" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<%
Do While (Not rs.Eof)
' Set row color
bgcolor = "#FFFFFF"
%>
<%
' Display alternate color for rows
If recCount Mod 2 <> 0 Then
bgcolor = "#F5F5F5"
End If
%>
<%
' Load Key for record
key = rs("accid")
If VarType(key) = 18 Or VarType(key) = 19 Then ' adUnsignedSmallInt/adUnsignedInt
If IsNull(key) Then
key = Null
Else
key = CInt(key)
End If
End If
x_accid = rs("accid")
x_accdesc = rs("accdesc")
x_acccost = rs("acccost")
%>
<tr bgcolor="#F5F5F5">
<td width="219" height="26"><span class="aspmaker"> <font size="1">
<font size="2"> <font color="#666666">
<%
Response.Write x_accdesc
Response.Write x_accid
%>
</font></font></font></span><font color="#666666" size="2"> </font></td>
<td width="67"><div align="center"><span class="aspmaker"><font color="#666666" size="2">
<strong>
<%
Response.Write "£" & x_acccost
%>
</strong> </font> </span></div></td>
<td width="43"><span class="aspmaker">
<%
x_stockaccList = "<select name='x_stockacc'><option value=''>Select</OPTION>"
sqlwrk = "SELECT `ynid`, `yn` FROM `tbl_yn`"
Set rswrk = Server.CreateObject("ADODB.Recordset")
rswrk.Open sqlwrk, conn, 1, 2
If Not rswrk.Eof Then
datawrk = rswrk.GetRows
rowswrk = UBound(datawrk, 2)
For rowcntwrk = 0 To rowswrk
x_stockaccList = x_stockaccList & "<option value='" & datawrk(0, rowcntwrk) & "'"
If CStr(datawrk(0, rowcntwrk)&"") = CStr(x_stockacc&"") Then
x_stockaccList = x_stockaccList & " selected"
End If
x_stockaccList = x_stockaccList & ">" & datawrk(1, rowcntwrk) & "</option>"
Next
End If
rswrk.Close
Set rswrk = Nothing
x_stockaccList = x_stockaccList & "</select>"
Response.Write x_stockaccList
%>
</span></td>
</tr>
<%
rs.MoveNext
Loop
%>
</table>