Here we get all treatments from db and onclick I want to save the clicked treatment id.
      <?php
          global $treatments;
          foreach($treatments as $treatment){
            echo ' <li class='.$treatment['name'].' onclick=getTreatmentId('.$treatment['id'].')>'.$treatment['name'].'</li>';
          };
       ?>
I made a js function
      <script>
          function getTreatmentId(id){
            
            return id; 
          }
      </script>
And I want to use that id to get all items with the same treatment ID. Like this:
   <?php 
        global $iController;
        $items = $iController->getItemByTreatmentId(Here i want to send clicked id); 
        foreach($items as $item){
          echo '
          <div class="group">
          <div class="classic_manicure">
            <img src="'.$item['img_url'].'" alt="'.$item['name'].'" />
            <h3>'.$item['name'].'</h3>
            <p>'.$item['time'].' min</p>
            <p>'.$item['price'].'$</p>
            <button>BOOK IT</button>
          </div>
          ';
        }
        ?>
getItemByTreatmentId method :
  public function getItemByTreatmentId($id){
        $sql = "SELECT * FROM treatments_item WHERE treatment=$id";
        $treatments = mysqli_query($this->connection,$sql);
        $returnArray = array();
        while($row = mysqli_fetch_assoc($treatments)){
            array_push($returnArray, $row);
        }
        return $returnArray;
    }
 
    