0

I have this part here which generates me an array:

$ids_sektor = explode("/",$row['sektori']);

What i need is to echo all those values inside a select option... The html for my selectbox is:

 <select id="sektori_pergjegjes" name="sektori_pergjegjes">
                <option value="A">A</option>
                <option value="B">B</option>
                <option value="C">C</option>
                <option value="D">D</option>
                <option value="E">E</option>
</select>

I tried foreach but no success, i guess i'm doing something wrong, of cours ei am, some help please.

3
  • 2
    Show the value of $row['sektori'] and your foreach try. Commented Feb 28, 2013 at 15:23
  • hi, pls post an examlpe of how $row['sektori']looks like Commented Feb 28, 2013 at 15:23
  • Yes so, there are values like :A/B/C/D Commented Feb 28, 2013 at 15:24

2 Answers 2

2

It should work as follows:

   $row['sektori'] = "12/34/56";
   $ids_sektor = explode("/", $row['sektori'];

   foreach ($ids_sektor as $id) {
       echo "<option>$id</option>\n";
   }
Sign up to request clarification or add additional context in comments.

Comments

2

I'm not sure I understood the question well, but it should be done like that:

<select id="sektori_pergjegjes" name="sektori_pergjegjes">
<?php
    foreach($ids_sektor as $item)
    {
        $id = htmlspecialchars(item);
        echo('<option value="' . $id . '">' . $id . '</option>');
    }
?>
</select>

You may skip htmlspecialchars() when you're 100% sure there will be just A/B/C/D/E in your array.

1 Comment

ASP-style short tags make me cry. Also, HTML escape~

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.