|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: May 2001
Messaggi: 589
|
[ASP e SQL]Come cambio questa query???
Salve, ho questo problema: un amico mi ha chiesto di fare una modifica a un suo sito che in pratica è una galleria di immagini. Il programmatore non può (pare, boh, forse manco ha voglia di mettersi), e io mi intendo di html ma non molto di ASP e sql.
Questa galleria funziona così: io posso scegliere di quale anno posso vedere le immagini, con una select. Il mio amico mi ha chiesto di fare in modo che non ci sia più questa divisione per anno, ma che appaiano semplicemente 12-15 immagini per pagina, a partire dalle ultime inserite. Ho provato a cambiare la query inserendo "select * from quadri order by id desc" ma mi dà errore di sintassi. Non capisco come devo fare. Scusate l'enorme papiro, ma qualcuno può darmi una mano? Codice:
<% Set db = Server.CreateObject("ADODB.Connection") dbfile = Server.MapPath("database") & "\quadri.mdb" db.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & dbfile) ' Immagini, divise in 2 sottodirectory, ' una per le img grandi e una per le thumb, a loro volta nelle sottodir ' ci sono le cartelle con le img divise anno per anno ' ' le thumbs si chiamano t_immagine.jpg ad esempio. ' Esiste una subroutine, residente in un file esterno che ' quindi va incluso, che controlla se esiste la thumb e se ' non esiste la crea. dim immagini(1000) immPerPagina = 12 'valore che vuoi immPerRiga = 2 ' anche qui righe = immPerPagina/immPerRiga imagedir = "img_gall" thumbdir = "img_thumb" pag = CInt(Request.QueryString("pag")) if pag = 0 then pag = 1 end if mostra = Request.QueryString("mostra") function isImage(file) r = FALSE ext = right(file.Name, 4) if Ucase(ext) = ".JPG" then r = TRUE if Ucase(ext) = ".JPE" then r = TRUE if Ucase(ext) = "JPEG" then r = TRUE isImage = r end function %> <!-- #include file="thumb.asp" --> <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Galleria</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="stile.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" type="text/javascript"> <!-- function galleria(fa) { var scelta = fa.selectedIndex; self.location.href = fa.options[scelta].value; } function apriwin(url,nome,proprieta){ newWin = window.open(url,nome,'scrollbars=yes, resizable=yes, width=800, height=600'); } --> </script> </head> <body> <div id="container"> <!-- #include file="header.asp" --> <table width="723" border="0" cellspacing="0" cellpadding="0" id="galleria"> <tr> <td> <div id="selezione" align="right"> <form method="POST" action="mostrafoto.asp"> <strong> Anno/Year: </strong> <select name="vai" onChange="galleria(this)"> <% path = Server.MapPath(imagedir) set FSO = CreateObject("Scripting.FileSystemObject") set dir = FSO.GetFolder(path) for each subdir in dir.SubFolders if left(subdir.Name, 1) <> "_" then response.write "<option value='galleria_anno.asp?mostra=" response.write(replace(subdir.Name, " ", "%20")) response.write "'" if mostra = subdir.Name then response.write " selected" end if response.write ">" & subdir.Name & "</option>" & vbcrlf if mostra <= " " then mostra = subdir.Name end if end if next %> </select> </form> </div> </td> </tr> <tr> <td> <table align="center" cellpadding="0" cellspacing="2"> <% path = Server.MapPath(imagedir & "\" & mostra) t_path = Server.MapPath(thumbdir & "\" & mostra) set dir = FSO.GetFolder(path) if not FSO.FolderExists(t_path) then FSO.createFolder(t_path) set t_dir = FSO.GetFolder(t_path) set files = dir.Files totImmagini = 0 for each file in files if isImage(file) then immagini(totImmagini) = file.Name thumbname = thumbdir & "\" & mostra & "\t_" & immagini(totImmagini) if not FSO.FileExists(thumbname) then makeThumb mostra, immagini(totImmagini) totImmagini = totImmagini + 1 end if next if (totImmagini mod immPerPagina) = 0 then pagine = totImmagini/immPerPagina else pagine = totImmagini/immPerPagina + 1 end if i = (pag - 1) * immPerPagina for j = 1 to righe if i <= totImmagini then response.write "<tr>" for k = 1 to immPerRiga response.write "<td align='center'>" & vbcrlf foto = immagini(i) if i <= totImmagini and foto <> "" then 'modifico per mostrare i quadri tutti in fila partendo dagli ultimi inseriti query = "select * from quadri where anno=" & chr(34) & mostra & chr(34) query = query & " and thumb=" & chr(34) & foto & chr(34) set risposta = db.execute(query) c = risposta("codice") response.write "<a href='javascript:apriwin(" & chr(34) & "mostrafoto.asp?tipo=" subdir = Replace(mostra, " ", "%20") foto = Replace(foto, " ", "%20") response.write subdir & "&foto=" & foto & chr(34) response.write ")'><img src='" & thumbdir & "/" & subdir response.write "/t_" & foto & "' vspace='4' border='0' alt='" response.write risposta("codice") & " - " & risposta("anno") response.write "' class='bordonero'></a>" response.write "<br />" response.write "<span class='codice'>" response.write risposta("codice") & " - " & risposta("anno") response.write "</span>" else response.write " " end if i = i + 1 response.write "</td>" & vbcrlf next response.write "</tr>" end if next %> </table> <br /> <% response.write "<tr><td><div align='right' class='paginaz'>" if pagine >= 1 then for i = 1 to pagine if i = pag then response.write i & vbcrlf else response.write "<a href='galleria_anno.asp?mostra=" & mostra response.write "&pag=" & i & "'>" & i & "</a>" & vbcrlf end if next end if response.write "</div></td></tr>" %> </td> </tr> </table> <!-- #include file="piede.asp" --> </div> </body> </html>
__________________
Web Ultima modifica di Tama : 14-09-2007 alle 19:16. |
![]() |
![]() |
![]() |
#2 |
Member
Iscritto dal: Aug 2007
Messaggi: 152
|
non ho guardato il listato, io uso il linguaggio sql e nn mi risulta che un campo del data base possa ontenere degli spazi
tua "select * from quadri order by id desc" probabile "select * from quadri order by iddesc" |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
|
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
query = "select * from quadri where anno=" & chr(34) & mostra & chr(34)
query = query & " and thumb=" & chr(34) & foto & chr(34) Dovresti sostituire queste righe con la sola: query = ""select * from quadri order by codice desc" Però attenzione perché non è detto che basti questo, in quanto il sito aveva anche il sistema di navigazione per anno. |
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: May 2001
Messaggi: 589
|
E' dura...
Provando semplicemente a sostituire ottengo che vengono visualizzate 4 immagini del 1991 con i codici di 4 immagini del 2001 e mi sparisce la paginazione ![]() Andiamo a fare qualche altro tentativo irrazionale... ora la query è questa: 'query = "select * from quadri where anno=" & chr(34) & mostra & chr(34) query = "select * from quadri order by codice desc" query = query & " and thumb=" & chr(34) & foto & chr(34) e mi dà: Microsoft JET Database Engine error '80040e14' Errore di sintassi nella proposizione ORDER BY. /galleriadecr.asp, line 139 alla riga 139 sta scritto di eseguire la query: set risposta = db.execute(query) non mi piace la programmazione ![]()
__________________
Web Ultima modifica di Tama : 19-09-2007 alle 09:32. |
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: May 2006
Città: Wursteland
Messaggi: 1749
|
Codice:
'query = "select * from quadri where anno=" & chr(34) & mostra & chr(34) query = "select * from quadri order by codice desc" query = query & " and thumb=" & chr(34) & foto & chr(34) poi la seconda contiene un order by e dopo, nella terza riga, aggiungi un "and thumb=..." ovvio che dia errore, l´order by deve stare alla fine ![]() EDIT: vedo un apice all´inizio della prima riga ... cosa significa commento ?
__________________
Nintendo WIII 4d Turbo Intercooler - Sestium X 666 99,312 GHz - 6.984 Ram Σ(9999) MHz - HDD SATA 97e^(10) bytes 93³ rpm - ATI biberon X900z ∞Mb - Win Eight SP (1 > yours) 16 Valve |
![]() |
![]() |
![]() |
#8 |
Senior Member
Iscritto dal: May 2001
Messaggi: 589
|
acci... hai parecchia ragione...
correggo al volo... l'apice perché facendo delle prove faccio prima a commentare le righe piuttosto che riscriverle :-) ora magari un programmatore "serio" fa in altro modo, ma non è il mio caso....credo si noti
__________________
Web |
![]() |
![]() |
![]() |
#9 | |
Senior Member
Iscritto dal: May 2006
Città: Wursteland
Messaggi: 1749
|
Quote:
PS: Un programmartore serio non userebbe Microsoft ![]()
__________________
Nintendo WIII 4d Turbo Intercooler - Sestium X 666 99,312 GHz - 6.984 Ram Σ(9999) MHz - HDD SATA 97e^(10) bytes 93³ rpm - ATI biberon X900z ∞Mb - Win Eight SP (1 > yours) 16 Valve |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:48.