A
A
Andrey Angelovich Stock2018-04-27 12:19:27
PHP
Andrey Angelovich Stock, 2018-04-27 12:19:27

How to assign selected select option by value from PHP array?

Hello! There is an array:

Array (
 [0] => Array ( [id] => 14 [c_name] => toto [url] => https://ranking.com [repetition] => 3 [ton] => 3 [type] => 2 [date] => 12.04.2018 ) 
[1] => Array ( [id] => 15 [c_name] => toto [url] => https://ranking.com [repetition] => 1 [ton] => 2 [type] => 4 [date] => 12.04.2018 ) 
[2] => Array ( [id] => 16 [c_name] => toto [url] => https://ranking.com [repetition] => 2 [ton] => 2 [ton] [type] =>4 [date] => 12.04.2018 ) )

There is also a table with selects like
echo "<td class='sel1'><select name=$arr[$i]['url'] class='custom-select ton' >
    <option  value='0' selected>Не определена</option>
    <option value='1'>Положительная</option>
    <option value='2'>Отрицательная</option>
    <option value='3'>Нейтральная</option>
    <option value='4'>Нерелевантная</option>
  </select></td>";

This array has a [ton] whose value must be the value of option. Please tell me how to make the select with this value assigned to selected.
I don't need a loop and a table output. you just need to deal with the select
Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sonca-ca, 2018-04-27
@your_uncle

Display the select in a loop with a check if this is the desired option, set it to selected
Or after scripts set the desired select to the desired value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question