Jump to content

Displaying pictures through loops (a repetitive question sorry... :( )


superdinoyoshi

Recommended Posts

Okay, as I mentioned, ive noticed this comes up a lot... And i realize that your patience is short because this is my first post... Im just hoping im not the only one on this forum guilty of noobishnes...

Anyway, moving on... I've been working on a site, and I've been thinking on what would be the easiest way to display pictures, and being able to constantly update them. As horribly worded as that was, i will try to keep explaining. If i had named all my pictures... 001(directoryname).jpg or something like that, and dumped them all into a folder, which's index has a variable like $amount , and a call to a template php file... How would i go about getting a loop to run as many times as the variable $amount, and echo a code to display them at some point in the page.... Earlier i had been working with arrays, but this solution seems better, if its possible..

Oh and if this description is to hard to work from, just complain, and I'll try to word things better, or throw in diagrams, and bits of code to get my point across... Anyway, and help is much appreciated, and dont worry to much about this, as its no big deal, and there are more important things to work at. If you have some free-time though, it would be pretty nice if anyone might wanna look at this a bit
Link to comment
Share on other sites

[code]<?php
// not sure how you're getting the $amount number... probably a filesystem call of some sort

for($i=0;$i<$amount;$i++)
{
    echo "<img src=\"images/$image_name\" alt="whatever">"
}
?>[/code]

Now... you could do a variety of things to spice this up as well:

1) Get the imagesize() and throw that in the img tag
2) Store all the image information (minus the image itself) in a database so you can just throw all that out each time the page is called without calculating it on the fly (this would be faster and easier than using an array too).
3) Add in a divide/3 or whatever to display your images nicely.

I assume this is for some sort of gallery or something?!
Link to comment
Share on other sites

Yeah, kinda like a gallery, i have a template page I have been using for all the pages in my site, and now i was thinking of making separate specialized templates that feed off the same stylesheets, that way i dont need to make new tables all the time. As for a database, I think i have a few tables of MySQL at my host, but i was saving them in case i decided to put in some forums. I also don't need any information besides displaying the image, and maybe adding in a description with this code...
Link to comment
Share on other sites

Sorry about the double post, but i had another idea, if i dumped in a thumbnail, and displayed that, how would i link a thumbnail to the fullimage. Instead of databases or arrays, wouldn't it be possible to have 001thumb.jpg and the corresponding 001image.jpg and while in reality i would display the thumbnails using css or a table... What variable would be the current loop the loop is on?
[code]
<?php
for($i=0;$i<$amount;$i++)
{
    echo "<a href="$???image.jpg"><img src=\"images/$image_name\" alt="whatever"></a>"
}
?>
[/code]
Link to comment
Share on other sites

I'll edit this post when i get a page up...

But for now, i can try to word it better...
Instead of just displaying the original image, how would you display thumbnails that link to the original image?

Well, right now that loop displays images image1.jpg, image2.jpg, and so on based on the variable amount. Or something along those lines. What variable are you using in that script to put the number in the filename? Im very inept at php, so I can't even pick it out....
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.