03. januar 2003 - 12:22Der er
9 kommentarer og 1 løsning
sql problem
Jeg fik for lidt tid siden hjælp af Eagleeye til noget menusjov, således at jeg kan flytte id på menuer op og ned ift. hinanden:
<% Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.RecordSet") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.mappath("*.mdb")
'flyt op/ned dir = Request.QueryString("dir") if dir <> "" then oldId = Request.QueryString("SubMenuId") tempID = 0
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE SubMenuId " if dir = "op" then SQL = SQL & " < " & oldID & " ORDER BY SubMenuId DESC" 'newID = Int(oldId) - 1 else SQL = SQL & " > " & oldID & " ORDER BY SubMenuId" 'newID = Int(oldId) + 1 end if Response.Write SQL set rs = conn.Execute(SQL) newID = rs("SubMenuId")
SQL = "UPDATE submenus SET subMenuId = " & tempID & " WHERE subMenuId = " & oldID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & oldID & " WHERE subMenuId = " & newID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & newID & " WHERE subMenuId = " & tempID Conn.Execute(SQL) end if
Problem: Nu vil jeg så udbygge det således at det filtreres efter "MainMenuId" i min tabel. Dvs. at hvis jeg tilgår siden med fx. side.asp?MainMenuId=2 så vises kun de menuer (subMenuId) der "passer" med MainMenuId 2.
Og det vil sq' ikke helt som jeg vil.
Jeg har forsøgt med:
<% Dim rs__ColParam rs__ColParam = "1" If (Request.QueryString("MainMenuId") <> "") Then rs__ColParam = Request.QueryString("MainMenuId") End If %>
og
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE MainMenuId = " + Replace(rs__ColParam, "'", "''") + " AND SubMenuId "
Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.RecordSet") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.mappath("*.mdb")
'flyt op/ned dir = Request.QueryString("dir") if dir <> "" then oldId = Request.QueryString("SubMenuId") tempID = 0
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE MainMenuId = " + oldId + " AND SubMenuId " if dir = "op" then SQL = SQL & " < " & oldID & " ORDER BY SubMenuId DESC" 'newID = Int(oldId) - 1 else SQL = SQL & " > " & oldID & " ORDER BY SubMenuId" 'newID = Int(oldId) + 1 end if Response.Write SQL set rs = conn.Execute(SQL) newID = rs("SubMenuId")
SQL = "UPDATE submenus SET subMenuId = " & tempID & " WHERE subMenuId = " & oldID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & oldID & " WHERE subMenuId = " & newID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & newID & " WHERE subMenuId = " & tempID Conn.Execute(SQL) end if
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE MainMenuId = " + Request.QueryString("SubMenuId") + " AND SubMenuId " if dir = "op" then SQL = SQL & " < " & oldID & " ORDER BY SubMenuId DESC" 'newID = Int(oldId) - 1 else SQL = SQL & " > " & oldID & " ORDER BY SubMenuId" 'newID = Int(oldId) + 1 end if Response.Write SQL set rs = conn.Execute(SQL) newID = rs("SubMenuId")
<% Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.RecordSet") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.mappath("../../access/pecms.mdb")
'flyt op/ned dir = Request.QueryString("dir") if dir <> "" then oldId = Request.QueryString("SubMenuId") tempID = 0
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE SubMenuId " if dir = "op" then SQL = SQL & " < " & oldID & " ORDER BY SubMenuId DESC" 'newID = Int(oldId) - 1 else SQL = SQL & " > " & oldID & " ORDER BY SubMenuId" 'newID = Int(oldId) + 1 end if Response.Write SQL set rs = conn.Execute(SQL) newID = rs("SubMenuId")
SQL = "UPDATE submenus SET subMenuId = " & tempID & " WHERE subMenuId = " & oldID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & oldID & " WHERE subMenuId = " & newID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & newID & " WHERE subMenuId = " & tempID Conn.Execute(SQL) end if
'Udskriv formen.. 'Så er det nødvendigt at hendte min/max SubMenuId for der ikke sker fejl..: SQL = "SELECT min(SubMenuId) as minID, max(SubMenuId) as maxID FROM submenus " set rs = conn.Execute(SQL) maxID = rs("maxID") minID = rs("minID")
SQL = "SELECT SubMenuId, SubMenuTitle FROM submenus ORDER BY SubMenuId" set rs = conn.Execute(SQL)
do while not rs.EOF Response.Write "<tr>" Response.Write "<td>" & rs("SubMenuTitle") & "<td>"
if Int(rs("SubMenuId")) > minID then Response.Write "<td><a href=""?dir=op&SubMenuId="&rs("SubMenuId")&""">ryk op</a><td>" else Response.Write "<td>...<td>" end if if Int(rs("SubMenuId")) < Int(maxID) then Response.Write "<td><a href=""?dir=ned&SubMenuId="&rs("SubMenuId")&""">ryk ned</a><td>" else Response.Write "<td>...<td>" end if Response.Write "</tr>"
rs.MoveNext loop %> </table> <% 'Lukker for connection til databasen Conn.Close %>
problemet er så at de på siden når det udskrives skal sorteres efter MainMenuId som er hovedmenu punkterne, fordi man tilgår undermenu redigeringssiderne med side.asp?MainMenuId=2 osv.
<% Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.RecordSet") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.mappath("../../access/pecms.mdb")
'flyt op/ned dir = Request.QueryString("dir") if dir <> "" then oldId = Request.QueryString("SubMenuId") tempID = 0
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE SubMenuId " if dir = "op" then SQL = SQL & " < " & oldID & " ORDER BY SubMenuId DESC" 'newID = Int(oldId) - 1 else SQL = SQL & " > " & oldID & " ORDER BY SubMenuId" 'newID = Int(oldId) + 1 end if Response.Write SQL set rs = conn.Execute(SQL) newID = rs("SubMenuId")
SQL = "UPDATE submenus SET subMenuId = " & tempID & " WHERE subMenuId = " & oldID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & oldID & " WHERE subMenuId = " & newID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & newID & " WHERE subMenuId = " & tempID Conn.Execute(SQL) end if
'Udskriv formen.. 'Så er det nødvendigt at hendte min/max SubMenuId for der ikke sker fejl..: SQL = "SELECT min(SubMenuId) as minID, max(SubMenuId) as maxID FROM submenus " set rs = conn.Execute(SQL) maxID = rs("maxID") minID = rs("minID")
SQL = "SELECT SubMenuId, SubMenuTitle FROM submenus WHERE MainMenuId = " + Request.QueryString("MainMenuId") + " ORDER BY SubMenuId" set rs = conn.Execute(SQL)
do while not rs.EOF Response.Write "<tr>" Response.Write "<td>" & rs("SubMenuTitle") & "<td>"
if Int(rs("SubMenuId")) > minID then Response.Write "<td><a href=""?dir=op&SubMenuId="&rs("SubMenuId")&""">ryk op</a><td>" else Response.Write "<td>...<td>" end if if Int(rs("SubMenuId")) < Int(maxID) then Response.Write "<td><a href=""?dir=ned&SubMenuId="&rs("SubMenuId")&""">ryk ned</a><td>" else Response.Write "<td>...<td>" end if Response.Write "</tr>"
rs.MoveNext loop %> </table> <% 'Lukker for connection til databasen Conn.Close %>
<% Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.RecordSet") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.mappath("../../access/pecms.mdb")
'flyt op/ned dir = Request.QueryString("dir") if dir <> "" then oldId = Request.QueryString("SubMenuId") tempID = 0
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE MainMenuId = " + Request.QueryString("MainMenuId") + " AND SubMenuId " if dir = "op" then SQL = SQL & " < " & oldID & " ORDER BY SubMenuId DESC" 'newID = Int(oldId) - 1 else SQL = SQL & " > " & oldID & " ORDER BY SubMenuId" 'newID = Int(oldId) + 1 end if Response.Write SQL set rs = conn.Execute(SQL) newID = rs("SubMenuId")
SQL = "UPDATE submenus SET subMenuId = " & tempID & " WHERE subMenuId = " & oldID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & oldID & " WHERE subMenuId = " & newID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & newID & " WHERE subMenuId = " & tempID Conn.Execute(SQL) end if
'Udskriv formen.. 'Så er det nødvendigt at hendte min/max SubMenuId for der ikke sker fejl..: SQL = "SELECT min(SubMenuId) as minID, max(SubMenuId) as maxID FROM submenus " set rs = conn.Execute(SQL) maxID = rs("maxID") minID = rs("minID")
SQL = "SELECT SubMenuId, SubMenuTitle FROM submenus WHERE MainMenuId = " + Request.QueryString("MainMenuId") + " ORDER BY SubMenuId" set rs = conn.Execute(SQL)
do while not rs.EOF Response.Write "<tr>" Response.Write "<td>" & rs("SubMenuTitle") & "<td>"
if Int(rs("SubMenuId")) > minID then Response.Write "<td><a href=""?dir=op&SubMenuId="&rs("SubMenuId")&""">ryk op</a><td>" else Response.Write "<td>...<td>" end if if Int(rs("SubMenuId")) < Int(maxID) then Response.Write "<td><a href=""?dir=ned&SubMenuId="&rs("SubMenuId")&""">ryk ned</a><td>" else Response.Write "<td>...<td>" end if Response.Write "</tr>"
rs.MoveNext loop %> </table> <% 'Lukker for connection til databasen Conn.Close %>
<% Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.RecordSet") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.mappath("../../access/pecms.mdb")
'flyt op/ned dir = Request.QueryString("dir") if dir <> "" then oldId = Request.QueryString("SubMenuId") tempID = 0
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE MainMenuId = " + Request.QueryString("MainMenuId") + " AND SubMenuId " if dir = "op" then SQL = SQL & " < " & oldID & " ORDER BY SubMenuId DESC" 'newID = Int(oldId) - 1 else SQL = SQL & " > " & oldID & " ORDER BY SubMenuId" 'newID = Int(oldId) + 1 end if Response.Write SQL set rs = conn.Execute(SQL) newID = rs("SubMenuId")
SQL = "UPDATE submenus SET subMenuId = " & tempID & " WHERE subMenuId = " & oldID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & oldID & " WHERE subMenuId = " & newID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & newID & " WHERE subMenuId = " & tempID Conn.Execute(SQL) end if
'Udskriv formen.. 'Så er det nødvendigt at hendte min/max SubMenuId for der ikke sker fejl..: SQL = "SELECT min(SubMenuId) as minID, max(SubMenuId) as maxID FROM submenus " set rs = conn.Execute(SQL) maxID = rs("maxID") minID = rs("minID")
SQL = "SELECT SubMenuId, SubMenuTitle FROM submenus WHERE MainMenuId = " + Request.QueryString("MainMenuId") + " ORDER BY SubMenuId" set rs = conn.Execute(SQL)
do while not rs.EOF Response.Write "<tr>" Response.Write "<td>" & rs("SubMenuTitle") & "<td>"
if Int(rs("SubMenuId")) > minID then Response.Write "<td><a href=""?dir=op&MainMenuId=" & Request.QueryString("MainMenuId") & "&SubMenuId="&rs("SubMenuId")&""">ryk op</a><td>" else Response.Write "<td>...<td>" end if if Int(rs("SubMenuId")) < Int(maxID) then Response.Write "<td><a href=""?dir=ned&MainMenuId=" & Request.QueryString("MainMenuId") & "&SubMenuId="&rs("SubMenuId")&""">ryk ned</a><td>" else Response.Write "<td>...<td>" end if Response.Write "</tr>"
rs.MoveNext loop %> </table> <% 'Lukker for connection til databasen Conn.Close %>
<% Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.RecordSet") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.mappath("../../access/pecms.mdb")
'flyt op/ned dir = Request.QueryString("dir") if dir <> "" then oldId = Request.QueryString("SubMenuId") tempID = 0
SQL = "SELECT TOP 1 SubMenuId FROM submenus WHERE MainMenuId = " + Request.QueryString("MainMenuId") + " AND SubMenuId " if dir = "op" then SQL = SQL & " < " & oldID & " ORDER BY SubMenuId DESC" 'newID = Int(oldId) - 1 else SQL = SQL & " > " & oldID & " ORDER BY SubMenuId" 'newID = Int(oldId) + 1 end if Response.Write SQL set rs = conn.Execute(SQL) newID = rs("SubMenuId")
SQL = "UPDATE submenus SET subMenuId = " & tempID & " WHERE subMenuId = " & oldID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & oldID & " WHERE subMenuId = " & newID Conn.Execute(SQL) SQL = "UPDATE submenus SET subMenuId = " & newID & " WHERE subMenuId = " & tempID Conn.Execute(SQL) end if
'Udskriv formen.. 'Så er det nødvendigt at hendte min/max SubMenuId for der ikke sker fejl..: SQL = "SELECT min(SubMenuId) as minID, max(SubMenuId) as maxID FROM submenus WHERE MainMenuId = " + Request.QueryString("MainMenuId") set rs = conn.Execute(SQL) maxID = rs("maxID") minID = rs("minID")
SQL = "SELECT SubMenuId, SubMenuTitle FROM submenus WHERE MainMenuId = " + Request.QueryString("MainMenuId") + " ORDER BY SubMenuId" set rs = conn.Execute(SQL)
do while not rs.EOF Response.Write "<tr>" Response.Write "<td>" & rs("SubMenuTitle") & "<td>"
if Int(rs("SubMenuId")) > minID then Response.Write "<td><a href=""?dir=op&MainMenuId=" & Request.QueryString("MainMenuId") & "&SubMenuId="&rs("SubMenuId")&""">ryk op</a><td>" else Response.Write "<td>...<td>" end if if Int(rs("SubMenuId")) < Int(maxID) then Response.Write "<td><a href=""?dir=ned&MainMenuId=" & Request.QueryString("MainMenuId") & "&SubMenuId="&rs("SubMenuId")&""">ryk ned</a><td>" else Response.Write "<td>...<td>" end if Response.Write "</tr>"
rs.MoveNext loop %> </table> <% 'Lukker for connection til databasen Conn.Close %>
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.