-1
How can I group array results and mount select.
Database
PHP
<?php
$rsPA = $mysqli->query("SELECT * FROM provas_agendadas WHERE status = 'A' ");
foreach ($rsPA as $key => $rsRowPA){
$dis1[] = explode("," , $rsRowPA['disciplinas']);
}
echo '<pre>';print_r($dis1);echo '</pre>';
?>
Upshot:
Array
(
[0] => Array
(
[0] => EJA-1
)
[1] => Array
(
[0] => EJA-1
[1] => EJA-5
[2] => TTI-1
)
)
Explaining: From the array result, I will only pick up the number after the -
, Ex: EJA-1
, I just need the 1
, which is the discipline table ID.
Final result I would like
I thank everyone who can help me.
search on array_search, it should solve your problem: https://www.php.net/manual/en/function.array-search.php
– Diego
The name of the discipline will always follow exactly this model
<string>-<id>
? if so you can combine the functionssubstr
andstrrpos
to extract the id, like this$disciplina = 'eja-5'; $id = substr($disciplina, strrpos($disciplina, '-') + 1);
– Diego Martins
@Diegomartins yes always this model
<string><hifen><id>
– Tiago
@Diegomartins and select mounting, as it would look?
– Tiago
Well there depends a lot, if you are using some layout tool or if you are using code directly in html... Overall you can count the Ids within this foreach that is already there, and then a new for to create the tags
<option>
within the select.– Diego Martins
I’m doing it right in html
– Tiago