0

I'm just getting to know PHP so please bear with me if my question is not clear. I have a user registration page that collects a field called "zodiac" which is uploaded to the database. I can easily call the variable $zodiac and the value, let's say, "Aries" is displayed on the desired user's page depending on who is logged in. However, instead of the text, I'd like to display a corresponding image file on the page from my local drive. I've tried the "elseif" statements but it doesn't seem to be working. Although I do get an image with the statement it doesn't seem to change when I change users:

These are properly being loaded to the desired page:

$this->table->add_row("<b>".$username."</b>&ensp;&ensp;Age:".$age."&ensp;&ensp;".$zodiac);

if($zodiac='Aries') {
   echo '<img src="../assets/images/zodiac/Aries.png" width="45" height="35" />';
    }elseif($zodiac='Taurus') {
   echo '<img src="../assets/images/zodiac/Taurus.png" width="45" height="35" />';
    }elseif($zodiac='Gemini') {
   echo '<img src="../assets/images/zodiac/Gemini.png" width="45" height="35" />';

The "elseif" statement continues to the end.

Hope this makes sense. Thanks for any input.

Nagesh Katna
  • 679
  • 2
  • 7
  • 27
dreamerdan
  • 43
  • 7

1 Answers1

0

You are mixing the assignment operator = with the equality operator ==.

// assign 1 to variable a
$a = 1

// compare variable a with 1
$a == 1

So to fix your code:

if ($zodiac == 'Aries')
{
...
}

You'll find more info about the operators and how they work here: https://secure.php.net/manual/en/language.operators.assignment.php https://secure.php.net/manual/en/language.operators.comparison.php

8ctopus
  • 2,617
  • 2
  • 18
  • 25
  • Works well! Appreciate it and wondering if you might help me place the image value of the variable $zodiac. The elseif statement is a bit long and I'm trying to find the simplest way to have it in this table: $this->table->add_row("".$username."  Age:".$age."  ".$zodiac); if($zodiac=='Aries') { echo ''; }elseif($zodiac=='Taurus') { echo ''; – dreamerdan Jan 04 '19 at 18:53
  • you can completely get rid of the if, elseif stuff by doing so: echo ''; – 8ctopus Jan 05 '19 at 07:52
  • Done. Appreciate it! – dreamerdan Jan 05 '19 at 18:42