sql多表联合php,sql/php:在另一个表(多个表)上没有匹配项的联接

此篇博客讲述了如何使用SQL查询来获取私人训练师为特定客户分配的营养和训练计划,以便只显示与客户相关的数据,即使数据库中未包含教练外键。作者分享了遇到的绑定参数问题及解决方法,展示了如何通过搜索功能按私人教练ID过滤出相关客户信息。
摘要由CSDN通过智能技术生成

我有四张桌子:

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"]; ?>

" οnclick="return confirm('Are you sure?');">Delete

" οnclick="return confirm('Are you sure?');">Update

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值