Good day!

  • Need advice newbie! There is a table in phpmyAdmin "smeny".
  • Previously, it had only 2 values: 1 and 2. Accordingly, if a doctor has 1 in the Monday field, then the browser displays "1 shift", if 2, then 2 changes are displayed:

<?php echo ($smena['monday']==1)?'I смена':'II смена'; ?>

// if the value == 1 then 1 change is output, otherwise 2 change.

Now I add three more values: 3 — sick leave, 4 — weekend, and 5 — vacation.

How do you set all five values ​​for output in the browser, inside <?php echo ($smena['monday']==1)?'I смена':'II смена'; ?> <?php echo ($smena['monday']==1)?'I смена':'II смена'; ?> ?!

Thank you in advance!

  • Here you need to vote for the answers and mark the correct one. - ilyaplot
  • I know, that's just my reputation below 15 points, so while I pass! - Aibek Sydygaliev

2 answers 2

Chenit type

 <?php echo array(1=>'I смена' ,2=>'II смена' ,3=>'больничный' ,4=>'выходной' ,5=>'отпуск' )[$smena['monday']]; ?> 
  • Thank! Your answer has worked! - Aibek Sydygaliev

Thank you @Akina for the short answer! The result was this:

  • <td style="background:<?php echo array(1=>'lightgreen',2=>'pink', 3=>'cyan', 4=>'gold', 5=>'CadetBlue')[$smena['monday']];?>"><?php echo array(1=>'I смена', 2=>'II смена', 3=>'выходной', 4=>'больничный', 5=>'отпуск')[$smena['monday']]; ?></td>
  • This, together with staining the desired cell in the desired color: value 1 = light green and the inscription 'I shift', etc.
  • Why twice the same thing? doesn't it work 1 => 'lightgreen "I change' ? - Akina
  • Is it possible to combine style and value? I think it is unlikely to succeed! These are different types. Or you can cite the full version of <? Php echo .....?>> ??? - Aibek Sydygaliev
  • What does the types? you simply print string literals to the source of the page, and then the render will draw all this trash. The full version is: <td style = "background: <? Php echo array (1 => 'lightgreen" I change', 2 => 'pink "II change', 3 => 'cyan" output', 4 => ' gold "output", 5 => 'CadetBlue "vacation") [$ smena [' monday ']];?> "> </ td> - Akina
  • I tried. everything is lost! Because 1) You all included in the <td> property; 2) I don’t understand why in 'pink "II shift', it starts with single quotes, then double quotes go and ends again with single quotes? - Aibek Sydygaliev
  • The extra quote was. Corrected: <td style = "background: <? Php echo array (1 => 'lightgreen" I change', 2 => 'pink "II change', 3 => 'cyan" output', 4 => 'gold " output ', 5 =>' CadetBlue "vacation ') [$ smena [' monday ']];? >> </ td> - Akina