|
Posted by Martien van Wanrooij on 12/03/06 13:05
"Jerry Stuckle" <jstucklex@attglobal.net> schreef in bericht
news:GvmdnUVc-IGe1e_YnZ2dnUVZ_rCdnZ2d@comcast.com...
> That's because you still haven't answered the question - what's in
> foto_array after it has been populated?
>
Jerry first of all thanks for helping me so much. Anyway in both cases, both
with getFromMySql and with the addThumbnails functions the array is
populated with photos like like ceci2k600.jpg, ceci2k601.jpg etc.(I hope I
understood your question correctly) thats why the function toonoverzicht
works correctly in both cases. But as I said, with the getFromMySql
function some info is lost when one photo is shown. In my first posting I
didn't want to post a too large piece of code but now I think it is better
to post it completely. I have tried to make it as modular as possible but I
must admit I am not completely successfull in it. All kind of suggestions
are welcome of course :)
<?php class fotoAlbum
{
var $tmPrefix;//thumbnail prefix, by default it is q, I create my
thumbnails with irfanview but I am considering the gdi functions later
var $fotoPagina;//page that contains the script, default is
toonfoto.php
var $toevoeging;
var $foto_array = array();
var $dezePagina;
var $mysql = false; //only used to put an apology online, to show
that there are some errors on it
function __construct($tmPrefix="q", $fotoPagina =
"toonfoto.php",$toevoeging ="")
{
$this->tmPrefix = $tmPrefix;
$this->fotoPagina = $fotoPagina;
$this->toevoeging = $toevoeging;
}
function getFromMySql($bestandspatroon)
{
$this->mysql = true;
$db = mysql_connect("server", "login","password");
mysql_select_db("database",$db) or die ("FOUT: OPENEN
DATABASE MISLUKT");
$query = mysql_query("SELECT bestandsnaam from fotos where
bestandsnaam LIKE '{$bestandspatroon}%' order by bestandsnaam ASC",
$db);
while (list($bestandsnaam) = mysql_fetch_row($query))
{
$this->foto_array[] = $bestandsnaam;
}
mysql_close($db);
}
function addThumbnails($tn)
{
if (is_array($tn))
{
foreach($tn as $t)
{
$this->foto_array[]= $t;
}
}
else
{
$this->foto_array[] = $tn;
}
}
function arrayposition($haystack, $needle)//php seems not ta have a
standard function to do this, suggestions for improvement are welcome of
course
{
$getal = 0;
$lengte = count($haystack);
for ($i = 0; $i < $lengte; $i++)
{
if ($needle == $haystack[$i])
{
return $i;
}
}
return -1;
}
function toonOverzicht($kolommen, $cssClass = "thumb")/* show the
thumbnails, this one works correctly */
{ if($this->mysql){
?>
<p class= "krktitel" style =
"background-color:yellow"><marquee>Momenteel zijn wij bezig met een aantal
technische aanpassingen aan onze fotopagina's. Mogelijk werken deze pagina's
daarom niet geheel correct. Onze excuses voor het ongemak.</marquee></p>
<?php }
$this->dezePagina = $_SERVER['PHP_SELF'];
$teller = 0;
$lengte = count($this->foto_array);
print "<table width = \"600\"><tr>";
foreach($this->foto_array as $plaatje)
{
print "<td class = \"$cssClass\" align =
\"center\"><a href =\"$this->dezePagina?plaatje=$plaatje\"><img src =
\"$this->tmPrefix$plaatje\" align = \"center\"></a></td>\n";
$teller++;
if ($teller % $kolommen == 0 )
{
echo"</tr>\n";
if ($teller < $lengte) echo "<tr>";
}
}
while($teller % $kolommen > 0)
{
echo"<td class = \"$cssClass\"></td>";
$teller++;
}
echo "</tr></table>";
}
function toonEenFoto($foto)
{
$this->dezePagina = $_SERVER['PHP_SELF'];
$totaalFotos = count($this->foto_array);
$hoeveelste = $this->arrayposition($this->foto_array, $foto)
+ 1;
//$hoeveelste = array_search($foto, $this->foto_array);
echo "<span style =
\"color:#990000;font-size:smaller\";>Foto $hoeveelste van
$totaalFotos</span><br>";
$volgendeFoto = "";
$vorigeFoto = "";
/*previous picture*/
if ($hoeveelste > 1)
{
$vorigeFoto = $this->foto_array[$hoeveelste - 2];
$verwijzing = "<a href = \"$this->dezePagina";
$verwijzing .= "?plaatje=$vorigeFoto\"";
$verwijzing .= "> << Vorige << </a>";
echo $verwijzing;
}
else echo "<span style = \"color:lightgrey\"> << Vorige <<
</span>";
/* thumbnail page */
echo " - <a href =
\"$this->dezePagina\">Terug naar het
overzicht</a> - ";
/* next picture*/
if ($hoeveelste < $totaalFotos)
{
$volgendeFoto = $this->foto_array[$hoeveelste];
$verwijzing = "<a href = \"$this->dezePagina";
$verwijzing .= "?plaatje=$volgendeFoto\"";
$verwijzing .= "> >> Volgende >> </a>";
echo $verwijzing;
}
else echo "<span style = \"color:lightgrey\"> >> Volgende >>
</span>";
echo "<p style = \"text-align:center;width:600px\"><img src
= \"$foto\"></p>";
}
/* check whether the thumbnails have to be shown or only one picture */
function swapDisplay($kolommen)
{
$plaatje = $_GET['plaatje'];
if (isset($plaatje)&&file_exists($plaatje))
{
$this->toonEenFoto($plaatje);
}
else
{
$this->toonOverzicht($kolommen);
}
}
}
?>
Navigation:
[Reply to this message]
|