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: </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>
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: </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>