Hide existed values from database in a dropdown menu

Viewed 31

There are 3 options, ABC, and user already selected "A". Is it possible to automatically disable or hide option A.

I have successfully created a method that will check if the value already exists in the database. I am new to javascript. I tried using (.hide() & .show()) but no luck. Can I still use javascript inside php?

Here my's code:

public function check_location(){
            $stmt = $this->connect()->prepare("SELECT location FROM covers");

            if(!$stmt->execute()){
                $stmt = null;
                header("Location: ../select.php?error=statement_failed");
                exit();
            }
        
            $items = $stmt->fetchAll(PDO::FETCH_ASSOC);
            if($stmt->rowCount() > 0){
                foreach($items as $key => $item){
                    echo '<div class="category col-md-3 me-auto">';
                    echo    '<label for="size" class="form-label mt-2 mx-2">Category</label>';
                    echo        '<select name="size" class="form-select">';
                    echo            '<option value="'.($item['location']).'">'.($item['location']).'</option>';
                    echo        '</select>';
                    echo '</div>';
                }
            }
        }
0 Answers
Related