Page 1 of 1

Images

Posted: Tue Jan 11, 2011 8:47 pm
by pretender5552
I want to set it up depending on what class they choice they get a different image as their avatar how do I do this?

Re: Images

Posted: Tue Jan 11, 2011 11:17 pm
by Jackolantern
You just have to remember that PHP can output anything into the page HTML, and them make a dynamic image tag:

Code: Select all

<img src="<?php
    switch ($_SESSION['class']) {
        case 'warrior':
            echo "images/classpics/warrior.png";  //enter your url here
            break;
        case 'mage':
            echo "images/classpics/mage.png";
            break;
        case 'rogue':
            echo "images/classpics/rogue.png";
            break;
        default:
            //of course throwing exceptions (aka errors) is optional, but if the class isn't what you think, something is very wrong
            throw new Exception("Incorrect class data stored.");
            break;
} ?>" alt="avatar image" />