Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde amigos,
Tenho uma galeria de imagens e estou tentando ordenar as fotos por nome/número.
Aqui funciona normal mas chama de forma aleatória: http://www.zapy.com.br/galeria1
Aqui chama as miniaturas na sequencia, mas ao clicar abre a foto seguinte: http://www.zapy.com.br/galeria2
São dois arquivos.
fotos.php
<?
//include("../config.php");
$id = $_GET[id];
//$cidade = $_GET[cidade];
$sql = mysql_query("SELECT * FROM galeria where id='$id'");
$dados= mysql_fetch_array($sql);
$dir = "../images/eventos/$dados[id_franquia]/$dados[pasta]/"
;
if (strstr($pg,".")== TRUE){
$pg=ceil($pg);
$pg=$pg-1;
}
if (!$pg==0)$cont=0;
}
?>
<script language=Javascript1.2>
function makevisible(cur,which){
if (which==0)</SCRIPT>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="right" valign="top">
<table align="center" width="242" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" width="242" valign="top"><?
$handle = opendir($dir);
$ext = "jpg";
$indice = 0;
$ipp = 18;
while (false !== ($file = readdir($handle)))
{
$pathdata = pathinfo($file);
if (!is_dir($file) && ($pathdata["extension"] == strtolower($ext)) || ($pathdata["extension"] == strtoupper($ext)))
{
$imagens[$indice] = $file;
$indice++;
}
}
natcasesort($imagens);
reset($imagens);
$pagina = 1;
if ($_GET['pg'])
$pagina = $_GET['pg'];
$paginas = ceil(count($imagens) / $ipp);
$inicio = $pg * $ipp;
$thumb="thumbs.php?w=73&h=60&imagem=";
for ($i=$inicio; $i<($inicio+$ipp); $i++)
if($imagens[$i] != ""){
$cont=$cont+1;
?> $z++;
if($pg == $z){
$page = $ipp*$z+1;
}
}
//echo $page;
?>
<a href="zoom.php?id=<? echo $id?>&page=<? echo "$cont";?>" target="exibe_fotos"><img src="<? echo "$thumb$dir$imagens[$i]"; ?>" hspace="1" vspace="2" border="0" style="border:1px solid #333333;FILTER: alpha(opacity=100)" onmouseover="makevisible(this,0)" onmouseout="makevisible(this,1)"></a>
<? }?></td>
</tr>
</table></td>
</tr>
<tr><td height="11"></td></tr>
<tr>
<TD valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="middle">
<td width="70%" align="right" valign="top"><font color="#ffffff"> <strong>
<?
echo "Pág.: ";
for($i=0; $i<$paginas; $i++){
$url = "?id=$id&cidade=$cidade&pg=$i";
if ($i==$pg) {
echo "<font color='#FFFFFF' style='BACKGROUND-COLOR: orange'>".($i+1)."</font> ";
} else {
echo "<a href='$url'><font color='#ffffff'><strong>".($i+1)."</strong></font><
/a> ";
}
}
?>
</strong>
</font></td>
</tr>
<tr><td height="33"></td></tr>
</table>
</td>
</tr>
</table>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="242" height="70" colspan="2" align="center">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="242" height="50" colspan="2" align="center">
<table width="100%" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="43%"> </td>
<td width="57%"><p align="center"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="242">
<tr>
<td width="242" height="8" colspan="2"></td>
</tr>
</table>
zoom.php
<?
include("../conexao.php");
$id = $_GET[id];
$cidade = $_GET[cidade];
$sql = mysql_query("SELECT * FROM galeria where id='$id'");
$dados= mysql_fetch_array($sql);
$dir = "../images/eventos/$dados[id_franquia]/$dados[pasta]/"
;
?>
<script src="../janelas_popup.js" language="Javascript"></script> $page=1;
}
$handle = opendir($dir);
$ext = "jpg";
$indice = 2;
$ipp = 1;
while (false !== ($file = readdir($handle)))
{
$pathdata = pathinfo($file);
if (!is_dir($file) && ($pathdata["extension"] == strtolower($ext)) || ($pathdata["extension"] == strtoupper($ext)))
{
$imagens[$indice] = $file;
$indice++;
}
}
natcasesort($imagens);
reset($imagens);
$pagina = 1;
if ($_GET['page'])
$pagina = $_GET['page'];
$paginas = ceil(count($imagens) / $ipp);
$total = ceil(count($imagens));
$inicio = $page * $ipp;?>
<?
$pg2 = ceil($paginas/$qts_thumbs);
//echo "$paginas/$qts_thumbs=$pg2<br>";
/*if($page == "16"){
$var = "1";
//echo "<meta http-equiv=\"refresh\" content=\"0;URL=janela.php?id=$id&cidade=$cidade&pg=$var\"
>";
echo "<script>
window.open('janela.php?id=$id&cidade=$cidade&pg=$var', '_top');
</script>";
}
if($page < ($paginas-2)){
echo "
<script>
window.location = \"janela.php?id=$id&cidade=$cidade&pg=$var+1\";
return;
</script>
";
}//for ($i = $page; $i <= $page+14; $i++) {
?>
<table width="709" height="15" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="90%" height="15" bgcolor="#FFFFFF"><font color="#000000"><b>Evento:</b> <? echo "$dados[nome]";?></font></td>
<td width="10%" height="15"></td>
</tr>
<tr>
<td width="90%" height="15" bgcolor="#FFFFFF"><font color="#000000"><b>Data:</b> <? $data = explode("-", $dados[data]); echo "$data[2]/$data[1]/$data[0]";?></font>
</td>
<td width="10%" height="15"></td>
</tr>
</table>
<table width="640" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="640" align="center" rowspan="2" valign="top">
<table width="640" height="480" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="640" height="480" align="center" valign="middle"><img src="<? echo "$thumb$dir$imagens[$i]";?>" border="0"></td>
</tr>
<tr>
<td width="640" height="25" align="center" valign="middle" bgcolor="#FFFFFF">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="25">
<tr>
<td width="63%">
</td>
<td width="37%"></td>
</tr>
</table>
</td>
</tr>
</table>
<br></td>
<td width="63" align="center" valign="top"></td>
</tr>
<tr>
<td valign="top" align="center">
<table align="center" width="63" border="0" align="center" cellpadding="0" cellspacing="3">
<tr>
<td width="63" height="30" align="center"><div align="center">
<?
if ($page > 1){
$pag=$page - 1;
if($page > 0 && $page < 16){ $pg2 = "0"; }
if($page >= 16 && $page < 31){ $pg2 = "1"; }
if($page >= 31 && $page < 46){ $pg2 = "2"; }
if($page >= 46 && $page < 61){ $pg2 = "3"; }
if($page >= 61 && $page < 76){ $pg2 = "4"; }
if($page >= 76 && $page < 91){ $pg2 = "5"; }
if($page >= 91 && $page < 106){ $pg2 = "6"; }
if($page >= 106 && $page < 121){ $pg2 = "7"; }
if($page >= 121 && $page < 136){ $pg2 = "8"; }
if($page >= 136 && $page < 151){ $pg2 = "9"; }
if($page >= 151 && $page < 166){ $pg2 = "10"; }
if($page >= 166 && $page < 181){ $pg2 = "11"; }
if($page >= 181 && $page < 196){ $pg2 = "12"; }
if($page >= 196 && $page < 211){ $pg2 = "13"; }
if($page >= 211 && $page < 226){ $pg2 = "14"; }
if($page >= 226 && $page < 241){ $pg2 = "15"; }
if($page >= 241 && $page < 256){ $pg2 = "16"; }
if($page >= 256 && $page < 271){ $pg2 = "17"; }
if($page >= 271 && $page < 286){ $pg2 = "18"; }
if($page >= 286 && $page < 301){ $pg2 = "19"; }
if($page >= 301 && $page < 316){ $pg2 = "20"; }
//echo $pg2;
echo "<a href=?id=$id&page=" . ($pag) . "><img src=images/bt_vo.gif align='center' width=`53` height=`63` border=`0`></a>";
} else {
echo "<img src=images/bt_vo.gif align='center' width=`53` height=`63`>";
}
/*
$div=$page/$qts_thumbs;
for ($x=1;$x<99;$x++){
if ($div==$x){
$inter=0;
break;
}
}if ($div==1){
$div=0; $div=$div-1;
}
echo "<script language=Javascript>
window.open('fotos.php?dir=$dir&page=".($div)."$var1', 'fotos');
</SCRIPT>";
}?>
</div></td>
</tr>
<tr>
<td height="30"align="center" ><? if($page<$total) {
$pagp=$page+1;
echo "<a href=?id=$id&page=" . ($pagp) . "><img src=images/bt_av.gif align='center' width=`53` height=`63` border=`0`></a>";
} else { echo "<img src=images/bt_av.gif align='center' width=`53` height=`63` border=`0`>";}
?></td>
</tr>
</table></td>
</tr>
</table>
No exemplo onde puxa aleatório tenho:
natcasesort($imagens);
No exemplo seguinte, onde chama na sequencia mas abre o seguinte tenho:
sort($imagens);
O que fazer para chamar as miniaturas na sequencia e abrir a foto correta?
desde já agradeço,
Plunder
Bom dia Monan,
Veja a estrutura da tabela:
--
-- Estrutura da tabela galeria
--
CREATE TABLE IF NOT EXISTS `galeria` (
`id` int(4) NOT NULL auto_increment,
`nome` varchar(255) NOT NULL default '',
`data` date NOT NULL default '0000-00-00',
`local` varchar(255) NOT NULL default '',
`pasta` varchar(255) NOT NULL default '',
`foto01` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Extraindo dados da tabela galeria
--
INSERT INTO galeria (id, nome, data, local, pasta, foto01) VALUES
(1, 'Evento 1', '2005-10-08', 'Local 1', 'evento1', 'evento1_001.jpg'),
(2, 'Evento 2', '2006-10-08', 'Local 2', 'evento2', 'evento2_002.jpg');
Eu já tentei ordenar por foto01, mas não dá certo.
Pelo admin eu cadastro o evento (por exemplo, Evento 1), envio a primeira foto que será destaque (evento1_001.jpg) e depois envio os demais arquivos via FTP para dentro da pasta deste evento (no caso, evento1).
Este sistema é um remanescente da velha Galeria Brasil e sequencia as fotos através do arquivo php que apresentei aqui, especificamente natcasesort($imagens);. Usando o natcasesort as miniaturas não vem na sequência mas abre normalmente cada foto, se eu coloco apenas sort as miniaturas vem na sequência, mas ao clicar na miniatura ela não abre a foto correta, e sim, a seguinte (exemplo: clica 1 e abre 2, clica 3 e abre 3). Eu já tentei retirar do código o natcasesort($imagens);, mas aí não funciona nada.
Este é meu dilema. Se um evento for coberto do meio da tarde até a noite, por exemplo, então teria fotos aleatórias na galeria, de dia e de noite.
Sei que existem outras galerias, mas eu gosto dessa e sou teimoso. Mas pelo jeito é causa perdida.
Plunder.
cara, olha, não sei se entendi muito bem sua duvida.. mas no meu ver voce não deve utilizar estes comandos de ordenação... <b>natcasesort</b>!
não faz sentido voce utilizar um comando de ordenação sendo que a própria consulta ira te trazer ordenado.. conforme voce solicitar...
veja, imagine o seguinte quadro:
voce tem o site principal com todos os eventos listados em ordem por data pelo comando ("SELECT * FROM GALERIA ORDER BY DATA").
preview:
>
01/05/2010
- Festa do semáforo.
- Festa da Ana.
- Festa do João.
Cada tópico deste possui um link que leva para a página que ira exibir as miniaturas.. e neste link é enviado o nome do envento via get para a proxima pagina (que pode ser um popup).. mais ou menos assim:
<a href="teste.php?evento=festasemaforo">- Festa do semáforo.</a>
<a href="teste.php?evento=festaana">- Festa da Ana.</a>
<a href="teste.php?evento=festajoao">- Festa do João.</a>
dai na proxima tela voce obtem o valor do get.. e execute a seguinte sintaxe.
<?php
$evento = $_GET['evento'];
$sql = "SELECT * FROM GALERIA G WHERE G.EVENTO = '$evento' ORDER BY G.ID";
?>
dai voce tera o resultado...
como resultado você lista as imagens em miniaturas na sequencia q o sql trouxer.. e insira o link nas imagens com que faça a devida referencia para exibição e tamanho maior.. porém, indicando o id de cada foto para que na hora que o sistema for exibir a imagem ele saber qual a imagem que ele deve exibir.. entende?
Cara, voce esta querendo ordenar as imagens e exibilas em ordem....
então faça assim...
na sua tabela você cadastra as imagens em ordem..
dai na hora que você for realizar seu query, você muda o seu sql de:
SELECT * FROM galeria
para
SELECT * FROM galeria order by id
com isso a própria consulta trara os resultados ordenados, basta voce escrever os resultados na tela e boa.
sem precisar de toda essa sua lógica de ordenação.. rs
talvez isso te ajude.