Home > Backend Development > PHP Tutorial > 一个页面内需要查询多个表的内容,怎么操作?

一个页面内需要查询多个表的内容,怎么操作?

WBOY
Release: 2016-06-13 13:39:35
Original
846 people have browsed it

一个页面内需要查询多个表的内容,如何操作??
Course表
id teacherid classid name room remarks
教师号 班级号 课程名 教室 备注


Student表
Id Name Password classid
学号 姓名 密码 班级


已知student的id,需要通过查student表得到对应的classid,然后在通过Course查找对应班级的课程信息输出


写的语句是:
$result = mysql_query("SELECT * FROM course "."WHERE class="."select classid from student"."where id= '".$username."'".".",$conn);

想分成两个语句写,但又不知道怎样保存中间结果。

但是打开时,会出现如下错误信息:


求指点!


------解决方案--------------------
$result = mysql_query("SELECT * FROM course WHERE class=(select classid from student where id= '".$username."')",$conn);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template