我有以下两个表格 第一桌是学生
--------------------------------------------------------------------
| tag_id | name | colloge | department| class |dev_id|
|----------+------------+-------------+------------+--------+------|
| 00000022 | Jhon Rayan | Engineering | Computer | first | c01 |
--------------------------------------------------------------------
第二张表名为lecture_table
--------------------------------------------------------
| dev_tag| lecture_name| lecturer_name| start | end |
|--------+-------------+--------------+--------+-------|
| c01 | Math I | Jhon Simone | 08:30 | 10:30 |
--------------------------------------------------------
所以我需要在学生表中通过tag_id(00000022)进行查询,并从学生表中获取有关它的完整信息。然后将这个学生通过(dev_id)与lecture_table(dev_tag)进行比较,以获得仅与该学生相关的讲座从整个讲座表 我试图使用此查询但无法正常工作
$raw_results = mysql_query("SELECT s.tag_id
s.dev_id,
s.name,
s.colloge,
s.class,
lt.lecture_name
,lt.lecturer_name,
lt.dev_tag,lt.day,
lt.start,lt.end,
FROM students s INNER JOIN lecture_table lt ON s.dev_id = lt.dev_tag WHERE s.tag_id LIKE '%".$query."%' AND(`name` LIKE '%".$_SESSION['username']."%')") or die(mysql_error());
所以任何人都可以帮忙吗?
答案 0 :(得分:1)
将您的查询修改为
$raw_results = mysql_query(
"SELECT s.tag_id, s.dev_id, s.name, s.colloge, s.class,
lt.lecture_name ,lt.lecturer_name, lt.dev_tag,lt.day,
lt.start,lt.end
FROM students s JOIN lecture_table lt ON s.dev_id = lt.dev_tag
WHERE s.tag_id LIKE '%".$query."%'
AND(`name` LIKE '%".$_SESSION['username']."%')")
or die(mysql_error());
在From关键字前删除 ,
,并在 ,
SELECT s.tag_id
>