我仍在尝试了解 MVC 我有一个直接的 php/mysql 页面,该页面基本上通过获取 select * FROM table1 然后循环遍历结果集并在每个循环上运行 Join 以查找子项目信息来工作。
但我不知道如何将其拆分并在 MVC 中执行。
代码如下所示,任何帮助或正确方向的指针都会受到重视!
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM building";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
//for loop make a table
//this is the heading info
$b_id=mysql_result($result,$i,"id");
$address=mysql_result($result,$i,"address");
$description=mysql_result($result,$i,"description");
?>
<table width="772px" border="0" align="center" cellpadding="5" cellspacing="0">
<tr bgcolor="#4682B4" height="50">
<td width="5%"></td>
<td><font size="4" face="tahoma" color="white"><strong><? echo $address; ?><a href="http://localhost:8888/project-add.php?b_id=<? echo $b_id; ?>">Add Project</a></strong></font></td>
<td bgcolor="#4682B4" align="center" width="50%"><input id="lnk<? echo $i; ?>" type="button" value="[+] Expand" onclick="toggle_visibility('tbl<? echo $i; ?>','lnk<? echo $i; ?>');"></td>
</tr>
<tr>
<td colspan="3">
<table width="103%" border="1" cellpadding="5" cellspacing="0" id="tbl<? echo $i; ?>" class="tbl">
<?
$query="SELECT project.id AS p_id, project.name AS p_name, project.description AS p_des, project.building_id as p_b_id, building.id AS b_id, building.address AS b_name
FROM project JOIN building
ON project.building_id = building.id
WHERE building_id='$b_id'";
$proj_result=mysql_query($query);
$proj_num=mysql_numrows($proj_result);
$j=0;
while ($j < $proj_num) { //while 1
$p_id=mysql_result($proj_result,$j,"p_id");
$p_name=mysql_result($proj_result,$j,"p_name");
$p_des=mysql_result($proj_result,$j,"p_des");
$b_name=mysql_result($proj_result,$j,"b_name");
?>
<tr>
<td width="5%"></td>
<td width="45%"><? echo $p_name; ?></td>
<td width="50%" align="center">XXXXXXX</td>
</tr>
<?
$j++;
} //end while 1
?>
</table>
</td>
</tr>
</table>
<?
$i++;
}
mysql_close();
?>