Jump to content

Echo variable depending on it's number...


Gibbs

Recommended Posts

I'm looking for a better way to achieve what i'm trying to do...

At the moment I have a database entry that is a number below 5. I want to echo something the same amount of times the number is. So if the number is 1 then it draws one picture, if it's 2 then two pictures.

Now what I'm doing works, don't get me wrong, but surely there is a better and less time consuming method then what is being done below?

[code=php:0]if ($resulta['demerits'] == 1)
{
echo "<td width=\"18\"><img src=\"img/icons/demerit.jpg\" border=\"0\"></img></td>";
}
elseif ($resulta['demerits'] == 2)
{
echo "<td width=\"18\"><img src=\"img/icons/demerit.jpg\" border=\"0\"></img></td>";
echo "<td width=\"18\"><img src=\"img/icons/demerit.jpg\" border=\"0\"></img></td>";
}[/code]

Thanks for any replies :D
Link to comment
https://forums.phpfreaks.com/topic/35590-echo-variable-depending-on-its-number/
Share on other sites

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.