Dynamic Select from Database with selected attribute

Ask a question
1

I am having some trouble with my selects that I populate from my database. I stay in the same form after ich submit it and I want the select to show the Item that was last selected. I tried this:

if($success = mysqli_num_rows($query2) > 0) {
    echo "<select name='Abteilungen'>n      <option value=0>Alle</option>n";
    while ($row = mysqli_fetch_array($query2)) {
        echo "<option ";
        if ($row[Abteilungs_ID]== $test) { echo 'selected'; }
        echo "value='$row[Abteilungs_ID]'>$row[Name]</option>n";
    }
    echo "</select>";
}

In $test is the post of the form.

But it only gives me an Error: Use of undefined constant.

Thanks for your time

Coin iconoffer bounty
add comment

0 Answer

Your Answer