DS928
asked on
Displaying Image Based On Field Value
I am trying to display an image based on the value of a field. I am getting this error.
Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/s/t/dstr3/ html/MENUH EAD/Pages/ restpage.p hp:1) in /home/content/d/s/t/dstr3/ html/MENUH EAD/Pages/ restpage.p hp on line 427
Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/s/t/dstr3/
<?PHP
If ($Rating == ".5")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/Half.png');
}
elseif ($Rating == "1")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/1Head.png');
}
elseif ($Rating == "1.5")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/1andHalf.png');
}
elseif ($Rating == "2")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/2Heads.png');
}
elseif ($Rating == "2.5")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/2andHalf.png');
}
elseif ($Rating == "3")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/3Heads.png');
}
elseif ($Rating == "3.5")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/3andHalf.png');
}
elseif ($Rating == "4")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/4Heads.png');
}
elseif ($Rating == "4.5")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/4andHalf.png');
}
elseif ($Rating == "5")
{
header('Content-Type: image/x-png');
readfile('http://www.menuhead.net/Images/Icons/5Heads.png');
}
?>
Probably a switch would be better, but why not just have an array containing the strings?
You could set the index to the array with:
$idx=$rating/.5-1;
And go directly to the array to get the image.
Cd&
You could set the index to the array with:
$idx=$rating/.5-1;
And go directly to the array to get the image.
Cd&
ASKER
Could you show ne more?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window