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=$pg * 18;
} else {
$cont=0;
}
?>
<script language=JavaScript1.2>
function makevisible(cur,which){
if (which==0)
cur.filters.alpha.opacity=80
else
cur.filters.alpha.opacity=100
}
</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 = "";
while($z < "$paginas") {
$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>
<?
if(!isset($page) ){
$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;
for ($i = $inicio; $i < ($inicio + $ipp); $i++)
?>
<?
$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 (isset($inter) AND $div * $qts_thumbs < $page){
if ($div==1){
$div=0;
} else {
$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.
Edição feita por: Plunder, 05/05/2010, 15:34.










