Hello. A question. Immediately I apologize, since I do not understand much in PHP, but I know that these are just a few lines of code. So, I have the simplest admin panel, done the lessons on Youtube. Admin is the most simple, clean sheet and a couple of buttons. There is a database. How can I create 3 fields in the admin panel with color options, for example: Blue, yellow, red, fill them in the admin panel and display it on the site as a drop-down list, while keeping the choice back to the database, but to another table? In HTML, I think it will be like this:

<select> <option value="yellow">Желтый</option> <option value="blue">Синий</option> <option value="red">Красный</option> </select> 
Help the good people! All good)

    1 answer 1

    We get from the database a list of colors and the current color

     $colors=array('Синий','Красный','Желтый'); $current_color = 'Желтый'; // Обработка отправки формы по нажатию на submit if (isset($_POST['submit']) && isset($_POST['color'])){ $color=$_POST['color']; //Далее запись в БД, куда нужно, Хоть прямым запросом хоть используя ORM } 

    In the form of writing

     <?if (isset($colors)):?> <select name='color'> <?foreach($colors as $color):?> <option value="<?=$color?>" <?=$color==$current_color?'selected="selected"':''?>> <?=$color?> </option> <?endforeach?> </select> <?endif?> 

    Something like this, although if the colors are stored in the form of a reference book, then it is better to select color id in option value =. Well, process it and write it as the current color.