PDA

View Full Version : [ASP e SQL]Come cambio questa query???


Tama
14-09-2007, 15:36
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?

<%
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:&nbsp;</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 "&nbsp;"
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>

unlock
15-09-2007, 08:47
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"

cionci
15-09-2007, 09:33
tua "select * from quadri order by id desc"
E' giusta in quanto ordina la query per id con ordine discendente (desc)...è possibile specificare anche l'ordine ascendente (asc).

cionci
15-09-2007, 09:36
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.

Tama
16-09-2007, 17:32
Grazie, appena ritorno a lavorarci vi faccio sapere cosa succede.
Il sistema di navigazione per anno provo a toglierlo, non lo vuole più...

Tama
19-09-2007, 10:15
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 :(

trallallero
19-09-2007, 11:44
'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)

scusa ma la prima riga e´ inutile perche´ sovrascritta dsalla seconda.
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 ?

Tama
19-09-2007, 12:21
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

trallallero
19-09-2007, 12:55
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

ah ok

PS: Un programmartore serio non userebbe Microsoft :ciapet:

Tama
26-09-2007, 10:55
Finalmente aggiungendo una query che conta le immagini funziona


nquery = "select count (*) as tot from quadri"
set tq = db.execute(nquery)
totImmagini = tq("tot")