Skip to content
Advertisement

If statement to replace something in ECHO

while ($rows=sqlsrv_fetch_array($stmt))
{
    $autoincrement++;

    if ($rows[1] == 'ACROBAT')
    {
        $rows[1] = '<img src="img/class/icons/acrobat.png" height="60" width="60"> '.$rows[1].' <?php echo $rows[1];?>';
    }

    if ($rows[1] == 'PRIEST')
    {
        $rows[1] = '<img src="img/class/icons/priest.png" height="60" width="60"> '.$rows[1].' <?php echo $rows[1];?>';
    }

    if ($rows[1] == 'SWORDMASTER')
    {
        $rows[1] = '<img src="img/class/icons/swordsman.png" height="60" width="60"> '.$rows[1].' <?php echo $rows[1];?>';
    }

    if ($rows[1] == 'MERCENARY')
    {
        $rows[1] = '<img src="img/class/icons/mercenary.png" height="60" width="60"> '.$rows[1].' <?php echo $rows[1];?>';
    }

    if ($rows[1] == 'ALCHEMIST')
    {
        $rows[1] = '<img src="img/class/icons/alchemist.png" height="60" width="60"> '.$rows[1].' <?php echo $rows[1];?>';
    }
    
echo 
'
<tr id=io>
<td> '.$autoincrement.' </td>
<b> <td> <a style = "color:#AFA;" href="pvpprofile"> '.$rows[0].'</a> </td> </b> 
<td> '.$rows[1].'</td>
<td> '.$rows[2].' </td>
<!--  <td> '.$rows[3].' </td>
<td> '.$rows[4].' </td>
<td> '.$rows[5].' </td> -->
</tr>
';  

}

How would I replace $rows[1] all the way on the bottom with my if statement? I’m currently trying to bind icons to my sql result. I’ve got about 100 cases and I don’t think this if statement would be very effective either, but nevertheless I want to understand how I would even implement adding these icons in the first place.

TLDR: How to make my if statement efficiently go into the last echo statement? I have about 100 cases inside my SQL query before this, is it possible to print ECHO statements in this and resolve everything?

$sql = "
SELECT TOP 25 G.CharacterName,
Case G.Jobcode
     WHEN '1' THEN  'WARRIOR'
     WHEN '2' THEN  'ARCHER'
     WHEN '3' THEN  'SOCERESS'
     WHEN '4' THEN  'CLERIC'
     WHEN '5' THEN  'ACADEMIC'
     WHEN '6' THEN  'KALI'
     WHEN '7' THEN  'ASSASSIN'
     WHEN '8' THEN  'PLACEHOLDER'
     WHEN '9' THEN  'PLACEHOLDER'
     WHEN '10' THEN  'ANCESTOR'
     WHEN '11' THEN  'SWORDMASTER'
     WHEN '12' THEN  'MERCENARY'
     WHEN '14' THEN  'SHARPSHOOTER'
     WHEN '15' THEN  'ACROBAT' 
     WHEN '17' THEN  'ELEMENTALIST'
     WHEN '18' THEN  'MYSTIC'
     WHEN '19' THEN  'WARLOCK'
     WHEN '20' THEN  'PALADIN'
     WHEN '21' THEN  'MONK'
     WHEN '22' THEN  'PRIEST'
     WHEN '23' THEN  'GLADIATOR'
     WHEN '24' THEN  'MOONLORD'
     WHEN '25' THEN  'BARBARIAN'
     WHEN '26' THEN  'DESTROYER'
     WHEN '29' THEN  'SNIPER'
     WHEN '30' THEN  'ARTILLERY'
     WHEN '31' THEN  'TEMPEST'
     WHEN '32' THEN  'WINDWALKER'
     WHEN '35' THEN  'SALEANA'
     WHEN '36' THEN  'ELESTRA'
     WHEN '37' THEN  'SMASHER'
     WHEN '38' THEN  'MAJESTY'
     WHEN '41' THEN  'GUARDIAN'
     WHEN '42' THEN  'CRUSADER'
     WHEN '43' THEN  'SAINT'
     WHEN '44' THEN  'INQUISITOR'
     WHEN '45' THEN  'EXORCIST'
     WHEN '46' THEN  'ENGINEER'
     WHEN '47' THEN  'SHOOTING STAR'
     WHEN '48' THEN  'GEAR MASTER'
     WHEN '49' THEN  'ALCHEMIST'
     WHEN '50' THEN  'ADEPT'
     WHEN '51' THEN  'PHYSICIAN'
     WHEN '54' THEN  'SCREAMER'
     WHEN '55' THEN  'DARK SUMMONER'
     WHEN '56' THEN  'SOUL EATER'
     WHEN '57' THEN  'DANCER'
     WHEN '58' THEN  'BLADE DANCER'
     WHEN '59' THEN  'SPIRIT DANCER'
     WHEN '62' THEN  'CHASER'
     WHEN '63' THEN  'REAPER'
     WHEN '64' THEN  'RAVEN'
     WHEN '65' THEN  'PLACEHOLDER'
     WHEN '66' THEN  'PLACEHOLDER'
     WHEN '67' THEN  'BRINGER'
     WHEN '68' THEN  'LIGHT FURY'
     WHEN '69' THEN  'ABYSS WALKER'
     WHEN '72' THEN  'PIERCER'
     WHEN '73' THEN  'FLURRY'
     WHEN '74' THEN  'STINGBREEZER'
     WHEN '75' THEN  'AVENGER'
     WHEN '76' THEN  'DARK AVENGER'
     WHEN '77' THEN  'PATRONA'
     WHEN '78' THEN  'DEFENSIO'
     WHEN '79' THEN  'RUINA'
     WHEN '80' THEN  'HUNTER'
     WHEN '81' THEN  'SILVER HUNTER'
     WHEN '82' THEN  'HERETIC'
     WHEN '83' THEN  'ARCH HERETIC'
     WHEN '84' THEN  'MARA'
     WHEN '85' THEN  'BLACK MARA'
     WHEN '86' THEN  'MECHANIC'
     WHEN '87' THEN  'RAY MECHANIC'
     WHEN '88' THEN  'ORACLE'
     WHEN '89' THEN  'ORACLE ELDER'
     WHEN '90' THEN  'PHANTOM'
     WHEN '91' THEN  'BLEED PHANTOM'
     WHEN '92' THEN  'KNIGHTESS'
     WHEN '93' THEN  'AVALANCHE'
     WHEN '94' THEN  'RANDGRID'
     WHEN '95' THEN  'LAUNCHER'
     WHEN '96' THEN  'IMPACTOR'
     WHEN '97' THEN  'LUSTRE'
     WHEN '98' THEN  'PLAGA'
     WHEN '99' THEN  'VENA PLAGA'
END,
D.PVPWin, D.PVPLose, G.PvPExp, D.PVPGiveUp
FROM PvPRanking as G
INNER JOIN PVPScores as D
ON G.CharacterID = D.CharacterID
ORDER BY  RANK() OVER (ORDER BY TotalRank ASC )
";

Advertisement

Answer

Answer is that you are not able to change SQL results through an associative array. The way to get my desired result was to fix up the SQL query itself and display the image through the database.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement