Jump to content

Storing numbers in a database - and displaying images


lowe_22

Recommended Posts

Hi,

I've run into a spot of difficulty whilst trying to code a script -

I want to display 3 different images x number of times, where x is a number stored in a database.
I'll tell you the context:
I have a database of tournament wins with 4 columns: MemberID (which member has the wins...), 1st Places wins, 2nd place wins, 3rd place wins.
A number is stored in each of the columns representing the number of each place won. I basically want to display an image for each one: 1image for 1st place, 1 image for second etc.. but I want to display that image however many times depending on the number in the database.

For example, a member has 3 1st place wins, I want to display the image for a first place win 3 times on the page.

How could I go about doing this?

Thanks.
Presuming you know how to extract the data from the database, you can do the following:

[code]
<?php

$num = $row['number']; // you will need to amend $row['number'] to the correct reference from your table data

for ($x=0;$x<$num;$x++) {
echo "<img src=\"image.gif\">";
}

?>
[/code]
Yea, that helps a lot. thanks very much.

There was one other thing that I could do with some help on. that is as follows:

For every 10 images of a certain kind, a different image is displayed instead.

So, if the member had 14 1st place wins, the browser should print one 10wins image followed by four 1stwins images.
Understand?
Any ideas?

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.