I entered into the database of colors. '$ rascvet [0] $ rascvet [1] $ rascvet [2]'

As a result, like this: "Brown Black Green" or "Black White", etc.

I deduce from DB a line, I compare and on the screen there is a picture of a coloring or a combination of coloring.

There are a lot of options. For example: var1-black; var2-white black; var3 black gray etc
Will it be correct if for each option there is a separate condition and its own picture?
Or is there some more rational way?

Now I use If elseif elseif ...

$row = mysql_fetch_assoc($result); do { if ($row['rascvet'] == "Коричневый Белый ") echo <img>1</img>'; elseif ($row['rascvet'] == "Белый ") echo <img>2</img>; elseif ($row['rascvet'] == "Черный Зеленый ") echo <img>3</img>; /*и так далее*/ } 
  • code in the studio. From this text, little can be understood - teran
  • it is not clear. better write some example in a more human language and at least pseudocode - Alexey Shimansky
  • $opts = ['белый' => "2.jpg", ...] and <img src="<?= $opts[$row['rascvet']]?>"/> - teran
  • @teran, it won't work out that way, he has Black Tea, Green Tea, etc., etc. - Visman
  • one
    @Visman I already understood from the name of the $rascvet variable in the first sentence that it just wouldn't be: D - teran

1 answer 1

It is more rational to create pictures with the same name as in the database and, thanks to this, make a conclusion without conditions

 $row = mysqli_fetch_all($result, MYSQLI_ASSOC); echo "<img href=" . $row['rascvet'] . ".jpg">"