1
I have an array named $c that I made through a explode need to count with the for to see if it is Selected. The problem is that it echo option 2 or how many times there are records. Does anyone have any solution to this?
foreach($interesse_compra as $ic)
{
$c = explode(";",$ic->cidade);
}
for($i = 0; $i < count($c);$i++)
{
foreach($cidades as $cidade)
{
$select = $cidade->f_cidade == $c[$i] ? "selected" : "";
echo "<option value='".$cidade->f_cidade."'$select>".$cidade->f_cidade."</option>";
}
}
pq
$c = explode(";",$ic->cidade);
is inside the foreach? that way thecount()
will only be done in the last element of$interesse_compra
.– rray
Is it a multiple selection select? That is, you can have several options selected?
– KaduAmaral
foreach is there because I use codeigniter. But this part is normal. $c is dividing into 3 parts. I do the counting. Only in the count it is doubling my clear and obvious options because it is remaking the same process based on $C[$i]. Got it @rray?
– Rogers Corrêa
Yes it is a select of multiple choices... I am bringing the database data in the editing part and I need to know which ones were selected. Only they’re saved separated by Pono and comma. @Kaduamaral
– Rogers Corrêa
Why the
explode
is inside a foreach? If it’s a loop, all that code shouldn’t be inside it too?– KaduAmaral
You can ask the question the content of
$interesse_compra
and$cidades
? You can print them withvar_dump($interesse_compra)
and put output in question.– KaduAmaral