我有四张桌子:
Personal_trainer(personaltrainerID, name, age, location)
Client(clientID, name, age, location)
Nutrition_Plan(NutritionplanID, personaltrainerID, clientID)
Training_Plan(TrainingplanID, personaltrainerID, clientID)
我试图表明,当私人培训师创建营养/培训计划并将其分配给客户时,结果只会显示他们的特定客户,但他们在客户表中没有识别教练的外键(根据项目标准)。
我想知道培训/营养计划中必要加入的SQL是什么。我已经试了一段时间了,这是我的示例代码。
所需的输出是所有客户数据,前提是这些数据由特定培训师分配了培训或营养计划。
在语句中,我遇到了绑定参数的问题,因此只有具有客户机的用户才能看到他们的客户机。如果我使用指定的ID,我可以得到一个返回!
//code to search for a item from the database
// user can enter any character to search for a value from the db
if (isset($_POST['search']))
{
$valueToSearch = $_POST['ValueToSearch'];
$query = "select * from client WHERE concat(`clientID`, `name`, `age`, `sex`, `weight`, `height`, `yearsExperience`, `goal`, `injuries`, 'email')like'%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "select *
from client
where clientID in (select clientID from nutrition_plan where personaltrainerID=?)
or clientID in (select clientID from training_plan where personalTrainerID=?)";
$query->bind_param("i", $_POST[""]);
$search_result = filterTable($query);
}
//code to filter the db
function filterTable($query)
{
$connect = mysqli_connect("localhost:3308","root","","fypdatabase");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
while($row = mysqli_fetch_array($search_result))
{ //display the details from the db in the table with option to delete or update entry
?>
<?php echo $row["clientID"]; ?><?php echo $row["name"]; ?><?php echo $row["age"]; ?><?php echo $row["sex"]; ?><?php echo $row["weight"]; ?><?php echo $row["height"]; ?><?php echo $row["yearsExperience"]; ?><?php echo $row["goal"]; ?><?php echo $row["injuries"]; ?><?php echo $row["email"]; ?>