Jump to content


Photo

Changing Images Depending Upon Values In Ranking List


  • Please log in to reply
2 replies to this topic

#1 tooNight

tooNight
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 28 April 2006 - 08:30 AM

Hi there in my ladder I want to display a up arrow if playerRankings.pRankingScore is great than playerRankings.pPrevRankingScore or down arrow if less & if the values are the same the display the yellow no change diamond. I would like to display the image in <th>Points +/-</th> column. I have saved the images below to my server and they are in /images under the same filenames. Just wondering if anybody could help me out with this simple if statement?


[img src=\"http://contact14.ics.uci.edu/virus/images/down-arrow-red.gif\" border=\"0\" alt=\"IPB Image\" /]

[img src=\"http://www.westpoint.ltd.uk/example-reports/reports/files/static/arrow-up-green.png\" border=\"0\" alt=\"IPB Image\" /]

[img src=\"http://www.westpoint.ltd.uk/example-reports/reports/files/static/arrow-none.png\" border=\"0\" alt=\"IPB Image\" /]


<?php
require('library/db_connect.php');    // database connect script.
?>
<?php include 'library/header.inc'; ?>


<?php
 
    $query  = "SELECT playerRankings.pRankingsID, playerRankings.pRankingScore, playerRankings.pPrevRankingScore, users.username, users.playerName 
                         FROM playerRankings, users 
               WHERE (playerRankings.pRankingsID = users.username)
               ORDER BY playerRankings.pRankingScore DESC";
               
    $result = mysql_query($query) or die('Error : ' . mysql_error()); 

    print "<table border=1>\n<tr><th>Rank</th><th>Name</th><th>Score</th><th>Prev Score</th><th>Points +/-</th></tr>\n";
   
        $rank = 1;
    while ($row = mysql_fetch_assoc($result)) {

    print "<tr><td>{$rank}</td><td><a href=\"playerDetails.php?username=$row[username]\">$row[playerName]</a></td><td>{$row['pRankingScore']}</td><td>{$row['pPrevRankingScore']}</td><td></td><tr>\n";

    $rank++;
    }

    
    print "</tr>" .
          "</table>";



    
   
    
    
    

$db_object->disconnect();
?>

<?php include 'library/footer.inc'; ?>


#2 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 28 April 2006 - 09:50 AM

Would something like this work?

if($row[pRankingScore] > $row[pPrevRankingScore){
    $img = "arrow-up-green.png";
}
elseif($row[pRankingScore] < $row[pPrevRankingScore){
    $img = "down-arrow-red.gif";
}
else{
    $img = "arrow-none.png";
}

then wherever you need the image

<img src="images/<?=$img?>">

If you're not part of the solution, you're part of the precipitate

#3 tooNight

tooNight
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 28 April 2006 - 10:04 AM

Yes works a treat, thanks matey.

Had to close the ] on the pRankingScore of the IF statement but apart from that it was fine.

Thanks alot





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users