Images

C++, C#, Java, PHP, ect...
Post Reply
pretender5552
Posts: 127
Joined: Mon Jan 03, 2011 5:38 am

Images

Post 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?
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Images

Post 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" />
The indelible lord of tl;dr
Post Reply

Return to “Coding”