如何创建双选查询

时间:2017-04-20 20:18:29

标签: php mysql

<?
session_start();
$username = $_SESSION["username"]; 
$lecturername = "SELECT lecturername FROM lecturer WHERE username='$username'";
$sql = "SELECT * FROM publication WHERE lecturername='$lecturername'";
$records = mysql_query($sql);   
?>

1 个答案:

答案 0 :(得分:1)

尝试使用这样的joins(仅举例):

SELECT * FROM lecturer t1 JOIN publication t2 ON (t1.lecturername = t2.lecturername) WHERE username='$username'

这将返回组合表讲师和出版物的数据,使用用户名来过滤讲师表的结果,从而过滤出版物。