Page 1 of 1

can't come up with a topic for this prob

Posted: Mon Sep 15, 2003 3:53 pm
by plastic
hmm... i have got stuck with this problem a couple of times...!
when i for example want to create a thumbnail.
and when i do this i have already created a file called "settings.php" with some information conserning the different thumbs in it. for example the url to the different thumbs.
I have called them $url1 = "clowns" and $ url2 = "beach" and so on.
And then i have one named $Amount where the total number of thumbs is.

Then i have created a for-funktion to create a table on the webpage... this is where my problem is. In the for-funktion i have a variable called $i... like for($i=1;$i<=$Amount;$i++). and everytime $i gets a new number i want the funktion to sen out a line like "<td><a target =\"main\" href=\"fbilder/$url1/thumb.php\"><img src=\"fbilder/$url1/$thumbname\" border=\"0\"></a></td>\n".
but how tha *** do i change the "url1" to "url2" and so on... depending on what number $i has??
i hope someone can understand my problem... i hate this problem... i want it to burn in hell :D!
peace be with ya all!

Posted: Mon Sep 15, 2003 4:01 pm
by SantaGhost
try this

Code: Select all

<?php
$Amount = 2;
$url = array("picture1","picture2");

for($i=0;$i<$Amount;$i++){
	echo "<td><a target ="main" href="fbilder/".$url[$i]."/thumb.php"><img src="fbilder/".$url[$i]."/$thumbname" border="0"></a></td>\n";
}
?>
but id rather do something like this:

thumbs.php

Code: Select all

<?php
$Amount = 2;
$url = array("picture1","picture2");

for($i=0;$i<$Amount;$i++){
	echo "<td><a target ="main" href="images.php?image=".$url[$i].""><img src="thumbs/".$url[$i].".jpg" border="0"></a></td>\n";
}
?>
images.php

Code: Select all

<?php
echo "<img src="images/".$_GET["image"].".jpg">";
?>

Posted: Tue Sep 16, 2003 4:06 am
by pootergeist
or you could use variable variables to generate the $url1 $url2 etc references

for($i = 0; $i < $Amount; $i++)
{
$tmp = 'url'.($i + 1);
echo $$tmp;
}

the $$tmp would then evaluate to $url1 on the first iteration, $url2 on the second etc.

As SantaGhost noted though, getting used to arrays may well be a better approach - depends upon the medium you currently hold the information in.

thank you

Posted: Tue Sep 16, 2003 5:43 am
by plastic
thank you both... this will solv my problem!
that i didn't think of arrays... stupid =)!