大家好, 以下是我的表
Table:- Project
-Project_ID (primary)
-ProjectName
Table:- Task
-Task_ID ( primary)
-project_ID
-TaskName
我想从项目表中选择任务名称。我该怎么做?
答案 0 :(得分:0)
mysql_query("select TaskName from Project left join Task on Project.Project_ID = Task.project_ID")
答案 1 :(得分:0)
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"select P.Project_ID, P.ProjectName, T.Task_ID,".
" T.TaskName from Task T".
" left outer join Project P on P.Project_ID=T.project_ID");
while($row = mysqli_fetch_array($result))
{
echo $row['Project_ID'] . " " . $row['Project_ID'];
echo $row['ProjectName'] . " " . $row['ProjectName'];
echo $row['Task_ID'] . " " . $row['Task_ID'];
echo $row['TaskName '] . " " . $row['TaskName '];
echo "<br>";
}
mysqli_close($con);
?>