我有 4 张桌子
Tbl_Items:
Asset Id,
Asset_name,
Workshop,
PAT_PASS
(workshop 和 PAT_PASS 是 YES 或 NO。Workshop = YES 和 PAT_PASS = NO 表示该项目不可租用..)
Tbl_Project_details:
Project_id,
Project_start_date,
project_end_date
TBL_Project_items:
Project_id,
Asset_id,
Start_date,
End_date
我需要做一个选择语句,允许我显示 tbl_Items 中的所有项目,除了:
1) Those that are already in use on another project on the dates that I need them.
2) Are in the workshop. (Workshop = YES)
3) Are not PAT Tested (PAT_PASS = NO)
到目前为止,我已经从这样一个简单的声明开始:
$post_project_id = "13-1309.01"; //this is just an example number..
$sql =
"SELECT * FROM Project_details
Where Project_id = '$post_project_id' ";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$hire_start_date = $row['Start_date']; // we find out our projects start date
$hire_end_date = $row['End_date']; // we find out our projects end date
}
$result=mysql_query("SELECT Items.Asset_id, Items.Name
FROM
Items,Project_items
WHERE
Project_details.Start_date < '$hire_start_date'
AND
Project_details.End_date > '$hire_end_date'")
or die(mysql_error());
while($row = mysql_fetch_array($result))
{
// fill up an option box with the results
}
即使这个基本脚本似乎也不起作用!这是我第一次尝试从多个表中进行选择,所以这是一个陡峭的学习曲线!
谢谢!