简体   繁体   English

两个表的内部联接[更新]

[英]Inner join of two tables [UPDATED]

tbl teacher tbl老师

lrn
fname
lname
email
image
schedule

tbl user tbl用户

lrn
fname
lname
email
image
account-type

$id=$_SESSION['id']; $ id = $ _ SESSION ['id'];

$get_record_sched = mysqli_query ($db, "SELECT schedule FROM teacher INNER JOIN users ON teacher.lrn = users.lrn WHERE teacher.lrn = '$id' "); $ get_record_sched = mysqli_query($ db,“从教师INNER JOIN用户上的选择时间表,在Teacher.lrn = users.lrn WHERE Teacher.lrn ='$ id'“);

I want to echo the exact schedule based on the id of the logged in account. 我想根据登录帐户的ID回显确切的计划。 But with this, query, there's no output... 但是有了这个查询,就没有输出了……

You said you have $id from the session. 您说您从会话中获得了$id Assuming that column lrn is the ID, then 假设lrn列是ID,则

Select t.schedule
From teacher t
Where t.lrn = $id

No need to join the table with the user table. 无需将表与用户表联接。

Note that parameter binding is advised. 请注意,建议使用参数绑定。

$statement = $connection->prepare("Select t.schedule From teacher t Where t.lrn = ?");
$statement->bind_param("s", $id);

In you where condition was wrong.They don't have any param to validate condition.so change like this 在您条件不正确的情况下,他们没有任何参数可以验证条件,因此应进行如下更改

"SELECT schedule FROM teacher INNER JOIN users  ON teacher.id = users.id WHERE 1  "

OR 要么

use same where condition with join 在join条件相同的地方使用

"SELECT schedule FROM teacher INNER JOIN users  ON teacher.id = users.id AND teacher.schedule = users.id   WHERE 1  "

OR 要么

if You have logged used id in session like 如果您已在会话中记录了已使用的ID,例如

$id=$_SESSION['user_id'];

"SELECT schedule FROM teacher INNER JOIN users ON teacher.id = users.id WHERE teacher.schedule='$id' "

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM