The form has a <select> of four <option>

 <select name=group size=1 onchange=""> <option name="pay_op" value="Приближение срока оплаты">Приближение срока оплаты</option> <option name="orders_op" value="Технические работы">Технические работы</option> <option name="news_op" value="Новости компании">Новости компании</option> <option name="other_op" value="Прочая информация">Прочая информация</option> </select> 

value from it is written to the field of the table, the structure of which is this:

enter image description here

In the field index2 wrote down numbers manually.

And you need to make sure that when you select a group in <select> , not only value automatically sent to the database, but also the corresponding index2 .

That is, in the form I choose “Approximation of payment deadline” and at the same time “1” is written in the field index2 , I choose “Technical works” - it is recorded “2”, etc.

Can you hang on each option id-shnik, and implement it using onchange ? But so far I have no idea how.

UPDATE:

enter image description here

enter image description here

Selection from tables:

 $result = database_select("SELECT g.name AS group, m.title AS title, m.message AS message FROM `vixen_erps_messages_sms` m INNER JOIN `vixen_erps_messages_group` g ON g.group_id = m.index2"); 
  • So write in the value option value index2, and write it in the database. Group imagine as an array index2 => group and take text data from there to display the text group - ilyaplot
  • And at all strange at you structure. Create the Groups table, write to index2 group_id and print the name of the group from there, and do not write the id and name in one table. - ilyaplot
  • I have 2 more tables besides this one. This incidentally refers to the SMS mailing with which you helped me. Based on these indexes, I select groups to users and send SMS to a specific group to the user. That is, this index2 links 3 tables. I didn’t quite understand the array, I just have the name in value and it is recorded in the group. - luckydutch
  • And for what purpose do you write the name of the group in value, and not its index? It turns out, is there a table with groups? If so, show what fields are there and a query that displays the records from the table from the question - ilyaplot
  • To write this value in the group field. I just can't do it differently, the knowledge is still very weak. If I write index2 in value, then how can I create an array of message types and write them in the group field when I select in select? - luckydutch

1 answer 1

I suggest HTML to do this

 <select name=group size=1 onchange=""> <option value="1">Приближение срока оплаты</option> <option value="2">Технические работы</option> <option value="3">Новости компании</option> <option value="4">Прочая информация</option> </select> 

Add a table with groups

 group_id name 1 Приближение срока оплаты 2 Технические работы 3 Новости компании 4 Прочая информация 

Suppose a table from a question is called erps_messages_sms and a sample from this table is approximately the following select group, title, message from erps_messages_sms

Delete the group column and cast the query to this form:

 select g.name as group, m.title as title, m.message as message from erps_messages_sms m inner join groups g on g.group_id = m.index2 

The output will be the same result as in the first query.

  • name from the group table for some reason does not pull out. I made the groups table, the group field was removed from the message table, the query seems to be correctly composed, like you did. title and message are output, but name is not - luckydutch
  • Show the data of the first and second tables, as well as the entire query for the sample. - ilyaplot
  • Added to question - luckydutch
  • Apparently, the problem is not in this part - luckydutch
  • one
    Solved a problem. Not there request shoved. - luckydutch