这里我们从 db 和 onclick 获取所有治疗,我想保存点击的治疗 ID。
<?php
global $treatments;
foreach($treatments as $treatment){
echo ' <li class='.$treatment['name'].' onclick=getTreatmentId('.$treatment['id'].')>'.$treatment['name'].'</li>';
};
?>
我做了一个js函数
<script>
function getTreatmentId(id){
return id;
}
</script>
我想使用该 id 来获取具有相同处理 ID 的所有项目。像这样:
<?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 方法:
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;
}
FFIVE