There is a form: enter image description here

It has 4 <select> each with 2 points (on, off). When adding a user, only one of the four will be included .

They look like this:

 <select size=1 name=pay> <option value="Включен">Включен</option> <option value="Выключен">Выключен</option> </select> 

I fill in the Index2 field manually and send it to the database. But you need to make sure that when you select a particular <select> , index2 automatically goes to the index2 , corresponding to the select.

For example, I turn on "Technical work", disable everything else. In the field index2 in the table should be written "2".

The table looks like this:

enter image description here

Please tell me what ways this can be implemented.

  • one
    Write the PHP code that will take get index, index2 and write to the database. Then use jQuery.ajax to send a request to this handler during the change event of the select field. PROFIT - ilyaplot
  • Why for the choice on / off you use, but not checkboxes? Why do you store strings in the database, not numbers for the pay, orders, news and other fields? With your statement of the task, the pay, orders, news and other fields are not needed at all, maybe you can give them up completely? - slava
  • Because these lines are displayed in a table on the page. And for the operator who will work with it, the words look clearer than the numbers. How can I store numbers in the database, but I can’t think of lines yet. And how to make it clear to index2 that I’m also not aware of a particular select / checkbox selected. - luckydutch
  • All normal database stores numbers, not words. Unfortunately, I see a question from you every day and give a detailed answer, but I do not see any desire to independently understand the principles of the work of my decisions. Perhaps my first comment can be perceived as an answer, with the help of which the problem is solved. - ilyaplot
  • one
    I suggest using the radio button in your interface and just one index2 field in the database. This will be enough to solve your problem. When displaying the table to the operator, displaying words instead of numbers, I suspect, will be the next question. - slava

1 answer 1

I keep in the database of numbers:

 <select size=1 name=pay> <option value="1">Включен</option> <option value="0">Выключен</option> </select> <select size=1 name=orders> <option value="2">Включен</option> <option value="0">Выключен</option> </select> <select size=1 name=news> <option value="3">Включен</option> <option value="0">Выключен</option> </select> <select size=1 name=other> <option value="4">Включен</option> <option value="0">Выключен</option> </select> 

I bring the words to the page using the query:

 SELECT p.type_condition AS `pay`, o.type_condition AS `orders`, n.type_condition AS `news`, a.type_condition AS `other`, s.login AS `login`, s.telephone AS `telephone`, s.index AS `index` FROM `vixen_erps_services_sms` s LEFT JOIN `vixen_erps_services_type` p ON p.type_id = s.pay LEFT JOIN `vixen_erps_services_type` o ON o.type_id = s.orders LEFT JOIN `vixen_erps_services_type` n ON n.type_id = s.news LEFT JOIN `vixen_erps_services_type` a ON a.type_id = s.other