我有以下表格:
Universities( iduni, uniname )
Campuses( idcampus, iduni, campusname, campusaddress )
Projects( idproject, idcampus, projectname )
IndustryCode( idindustrycode, codenumber, description )
Specialization( idspec, specname )
以下是上面列出的一些表的关联表
CampusSpecialization( idcampus, idspec )
ProjectSpecialization( idproject, idSpec )
ProjectIndustryCode( idproject,idindustrycode )
我想通过 PHP 生成具有以下结构的 XML 文件,但无法弄清楚SELECT
从数据库中提取数据的语句。数据是每个项目的校园、大学、项目、行业代码和专业,以便稍后我可以根据这些相互关联的数据在我的小型应用程序中过滤结果。
<items>
<item>
<campus campusname="$CAMPUSNAME" uniname="$UNINAME" campusaddress="$CAMPUSADDRESS">
<projects>
<project>
<name>$PROJECTNAME</name>
<specs>
<spec>$SPECNAME1</spec>
<spec>$SPECNAME2</spec>
...
</specs>
<industries>
<industry>$CODENUMBER1</industry>
<industry>$CODENUMBER2</industry>
...
</industries>
</project>
...
</projects>
</campus>
</item>
<item>
<campus ... >
<projects>
<project ... >
...
</project>
</campus>
</items>
到目前为止,这是我的 SQL 语句:
SELECT
campusname,
specname,
projectname
FROM
Specialization,Projects
JOIN CampusSpecialization ON CampusSpecialization.idspec = Specialization.idspec
JOIN Campuses ON CampusSpecialization.idcampus = Campuses.idcampus
JOIN ProjectSpecialization ON ProjectSpecialization.idspec = Specialization.idspec
编辑:
项目可能有一个或多个代码和行业。