php连接查询多个表

时间:2012-05-30 12:29:02

标签: php join

任何人都可以告诉我如何获得project_title,project_id,level_of_want和selection_id的值。当我提交这个时,我得到No database selected错误。

$query_Name = "SELECT u.Student_Surname, u.Student_Forename, p2.Project_Title,     
p2.Project_id, s.level_of_want, s.selection_id
FROM users u
INNER JOIN projects p2 ON u.id = p2.Project_Lecturer
INNER JOIN selection s ON p2.Project_id = s.id_project
INNER JOIN users u2 ON s.student_id = u2.id
WHERE u2.Username = ".$_SESSION['MM_Username']." ORDER BY selection_id ASC" ;
$Name = mysql_query($query_Name, $projectsite) or die(mysql_error());
$row_Name = mysql_fetch_assoc($Name);
$totalRows_Name = mysql_num_rows($Name);

2 个答案:

答案 0 :(得分:1)

连接到mysql服务器库后,您应该使用mysql_select_db函数

显式选择数据库

答案 1 :(得分:1)

mysql_select_db($bd);

我们需要看看你如何连接