Showing a bunch of images

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Showing a bunch of images

Post by Xaos »

So, I want to show an image for each number in a certain variable (the variable is stock) So if there are 3000 in 'stock', 3000 of the image would be shown (I'm planning on small images, don't worry) Is it as simple as just putting the call to an img in a for loop? How would I do something that say, added a 'range' of where the image was as to avoid them all stacking on top of eachother? Also, I want to create a line graph based on three variables - total stock, total harvested and turns taken. The TOtal Stock and Total Harvested would be two different lines on the same graph and Turns would eb the X axis. Is there an easy-ish way to code this myself, or should I just google for some code for a graph and tie it into my code to receive my data?

Thanks for all the answers guys
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Showing a bunch of images

Post by Jackolantern »

Are the graph and 3000 images two different things, or are they part of one component?
The indelible lord of tl;dr
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Showing a bunch of images

Post by Xaos »

Jackolantern wrote:Are the graph and 3000 images two different things, or are they part of one component?


They'll use shared variables, but they are different entities.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Showing a bunch of images

Post by Jackolantern »

Well, for showing 3000 images without having them all stack one after another, you would just use a nested FOR loop, like:

Code: Select all

for ($i = 0; $i < 50; $i++) {
     for ($j = 0; $j < 60; $j++) {
          echo "<img src=\"icon.jpg\">";
     }
     echo "<br>";
}
Just alter the FOR loops for the dimensions of the rectangle or to change the shape all-together.

As for the graph, I would download a 3rd party library to do that, as fabricating graphs from scratch that actually look decent isn't worth the time when there are so many graphing libraries out there already.
The indelible lord of tl;dr
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Showing a bunch of images

Post by Xaos »

Jackolantern wrote:Well, for showing 3000 images without having them all stack one after another, you would just use a nested FOR loop, like:

Code: Select all

for ($i = 0; $i < 50; $i++) {
     for ($j = 0; $j < 60; $j++) {
          echo "<img src=\"icon.jpg\">";
     }
     echo "<br>";
}
Just alter the FOR loops for the dimensions of the rectangle or to change the shape all-together.

As for the graph, I would download a 3rd party library to do that, as fabricating graphs from scratch that actually look decent isn't worth the time when there are so many graphing libraries out there already.
Use like nested CSS and the for-loops to create the rectangle and fill it up basically?
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Showing a bunch of images

Post by Jackolantern »

Use any CSS you need, but you can create a rectangle of images (or even a triangle with a more complex nested for loop) with just raw HTML in the PHP.
The indelible lord of tl;dr
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: Showing a bunch of images

Post by Xaos »

Duh ! I wasn't even thinking! Thanks alot jacko.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Showing a bunch of images

Post by Jackolantern »

No problem :)
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”