Reply to Re: array / mysql question

Your name:

Reply:


Posted by Jerry Stuckle on 12/04/06 03:36

Martien van Wanrooij wrote:
>
> "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 "&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;<a href =
> \"$this->dezePagina\">Terug naar het
> overzicht</a>&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;";
> /* 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);
> }
> }
>
>
>
>
> }
> ?>

Hi, Martien,

Sorry if my last response sounded a bit abrupt. I just re-read it, and
the tone wasn't what I planned. That's what I get for responding when
I'm tired :-(.

OK, the class itself looks OK, from what I saw (but I didn't go into a
lot of depth).

OK, you think the class is populated correctly before you display a
picture. Have you actually printed out the contents of $foto_array at
the end of the getFromMySql() function? I never assume something should
be there - I *always* print it out to make sure! :-)

And you say when you display the first picture, "some information is
being lost". How are you saving the information in the class? Are you
putting it in a session, for instance? Or are you pulling the
information from the database again? If the latter, again, what are the
contents for $foto_array at the end of getFromMySql()?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация