Page 1 of 1
Showing a bunch of images
Posted: Wed Oct 30, 2013 2:17 am
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
Re: Showing a bunch of images
Posted: Wed Oct 30, 2013 3:35 am
by Jackolantern
Are the graph and 3000 images two different things, or are they part of one component?
Re: Showing a bunch of images
Posted: Wed Oct 30, 2013 11:54 am
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.
Re: Showing a bunch of images
Posted: Wed Oct 30, 2013 3:15 pm
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.
Re: Showing a bunch of images
Posted: Wed Oct 30, 2013 3:23 pm
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?
Re: Showing a bunch of images
Posted: Wed Oct 30, 2013 8:22 pm
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.
Re: Showing a bunch of images
Posted: Wed Oct 30, 2013 9:17 pm
by Xaos
Duh ! I wasn't even thinking! Thanks alot jacko.
Re: Showing a bunch of images
Posted: Wed Oct 30, 2013 10:04 pm
by Jackolantern
No problem
