我有一个包含3个表的数据库,每个表有6到20行,但我的PHP代码创建了8个表,当时应该只有2个(数据库中有2个帖子)
但为什么会这样做,我从不同的PHP页面获取代码,它在哪里工作正常?
<?php
session_start();
require_once("connect.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Brand check</title>
</head>
<body>
<br />
<br />
<?php
$query = mysql_query("SELECT * FROM under_etage, sal_1, sal_2") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
?>
<table width="1100" border="0" align="center" cellpadding="0" cellspacing="0"lass="bold_font">
<tr>
<td width="150" height="25" class="info"> <?php echo $row["etDate"]; ?></td>
<td width="100" height="25" class="info"> Lys</td>
<td width="100" height="25" class="info"> Skilt</td>
<td width="100" class="info" > Brandtæppe</td>
<td width="100" class="info"> Brand sprøjte</td>
<td width="500" class="info"> Døre</td>
</tr>
<tr>
<td height="20" class="split">Underetage</td>
<td width="50" class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
</tr>
<tr>
<td class="sort_bar">Opgang A</td>
<td width="50" height="25" class="info" ><?php echo $row["lys_u_a"]; ?></td>
<td class="info"><?php echo $row["skilt_u_a"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_a"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">Studie/gang</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_s"]; ?></td>
<td class="info"><?php echo $row["skilt_u_s"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_s"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">Opgang B</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_b"]; ?></td>
<td class="info"><?php echo $row["skilt_u_b"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_b"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">Bar - Festrum</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_bar"]; ?></td>
<td class="info"><?php echo $row["skilt_u_bar"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"> </td>
</tr>
<tr>
<td height="25" class="sort_bar">Opgang C</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_c"]; ?></td>
<td class="info"><?php echo $row["skilt_u_c"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_c"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">Opgang D</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_d"]; ?></td>
<td class="info"><?php echo $row["skilt_u_d"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_d"]; ?> </td>
</tr>
<tr>
<td height="20" class="split">Etager</td>
<td width="50" class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
</tr>
<tr>
<td class="grey_bar">1. Sal A</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_1a"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_1a"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_1a"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_1a"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_1a"]; ?></td>
</tr>
<tr>
<td class="grey_bar">1. Sal B</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_1b"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_1b"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_1b"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_1b"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_1b"]; ?></td>
</tr>
<tr>
<td class="grey_bar">1. Sal C</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_1c"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_1c"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_1c"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_1c"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_1c"]; ?></td>
</tr>
<tr>
<td class="grey_bar">1. Sal D</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_1d"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_1d"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_1d"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_1d"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_1d"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">2. Sal A</td>
<td width="50" height="25" class="info"><?php echo $row["lys_2a"]; ?></td>
<td class="info"><?php echo $row["skilt_2a"]; ?></td>
<td class="info"><?php echo $row["bt_2a"]; ?></td>
<td class="info"><?php echo $row["bs_2a"]; ?></td>
<td class="info"><?php echo $row["doors_2a"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">2. Sal B</td>
<td width="50" height="25" class="info"><?php echo $row["lys_2b"]; ?></td>
<td class="info"><?php echo $row["skilt_2b"]; ?></td>
<td class="info"><?php echo $row["bt_2b"]; ?></td>
<td class="info"><?php echo $row["bs_2b"]; ?></td>
<td class="info"><?php echo $row["doors_2b"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">2. Sal C</td>
<td width="50" height="25" class="info"><?php echo $row["lys_2c"]; ?></td>
<td class="info"><?php echo $row["skilt_2c"]; ?></td>
<td class="info"><?php echo $row["bt_2c"]; ?></td>
<td class="info"><?php echo $row["bs_2c"]; ?></td>
<td class="info"><?php echo $row["doors_2c"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">2. Sal D</td>
<td width="50" height="25" class="info"><?php echo $row["lys_2d"]; ?></td>
<td class="info"><?php echo $row["skilt_2d"]; ?></td>
<td class="info"><?php echo $row["bt_2d"]; ?></td>
<td class="info"><?php echo $row["bs_2d"]; ?></td>
<td class="info"><?php echo $row["doors_2d"]; ?></td>
</tr>
<tr>
<td class="grey_bar">3. Sal A</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_3a"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_3a"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_3a"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_3a"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_3a"]; ?></td>
</tr>
<tr>
<td class="grey_bar">3. Sal B</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_3b"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_3b"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_3b"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_3b"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_3b"]; ?></td>
</tr>
<tr>
<td class="grey_bar">3. Sal C</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_3c"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_3c"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_3c"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_3c"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_3c"]; ?></td>
</tr>
<tr>
<td class="grey_bar">3. Sal D</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_3d"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_3d"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_3d"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_3d"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_3d"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">4. Sal A</td>
<td width="50" height="25" class="info"><?php echo $row["lys_4a"]; ?></td>
<td class="info"><?php echo $row["skilt_4a"]; ?></td>
<td class="info"><?php echo $row["bt_4a"]; ?></td>
<td class="info"><?php echo $row["bs_4a"]; ?></td>
<td class="info"><?php echo $row["doors_4a"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">4. Sal B</td>
<td width="50" height="25" class="info"><?php echo $row["lys_4b"]; ?></td>
<td class="info"><?php echo $row["skilt_4b"]; ?></td>
<td class="info"><?php echo $row["bt_4b"]; ?></td>
<td class="info"><?php echo $row["bs_4b"]; ?></td>
<td class="info"><?php echo $row["doors_4b"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">4. Sal C</td>
<td width="50" height="25" class="info"><?php echo $row["lys_4c"]; ?></td>
<td class="info"><?php echo $row["skilt_4c"]; ?></td>
<td class="info"><?php echo $row["bt_4c"]; ?></td>
<td class="info"><?php echo $row["bs_4c"]; ?></td>
<td class="info"><?php echo $row["doors_4c"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">4. Sal D</td>
<td width="50" height="25" class="info"><?php echo $row["lys_4d"]; ?></td>
<td class="info"><?php echo $row["skilt_4d"]; ?></td>
<td class="info"><?php echo $row["bt_4d"]; ?></td>
<td class="info"><?php echo $row["bs_4d"]; ?></td>
<td class="info"><?php echo $row["doors_4d"]; ?> </td>
</tr>
<tr>
<td class="grey_bar">5. Sal A</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_5a"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_5a"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_5a"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_5a"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_5a"]; ?></td>
</tr>
<tr>
<td class="grey_bar">5. Sal B</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_5b"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_5b"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_5b"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_5b"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_5b"]; ?></td>
</tr>
<tr>
<td class="grey_bar">5. Sal C</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_5c"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_5c"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_5c"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_5c"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_5c"]; ?></td>
</tr>
<tr>
<td class="grey_bar">5. Sal D</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_5d"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_5d"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_5d"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_5d"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_5d"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">6. Sal A</td>
<td width="50" height="25" class="info"><?php echo $row["lys_6a"]; ?></td>
<td class="info"><?php echo $row["skilt_6a"]; ?></td>
<td class="info"><?php echo $row["bt_6a"]; ?></td>
<td class="info"><?php echo $row["bs_6a"]; ?></td>
<td class="info"><?php echo $row["doors_6a"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">6. Sal B</td>
<td width="50" height="25" class="info"><?php echo $row["lys_6b"]; ?></td>
<td class="info"><?php echo $row["skilt_6b"]; ?></td>
<td class="info"><?php echo $row["bt_6b"]; ?></td>
<td class="info"><?php echo $row["bs_6b"]; ?></td>
<td class="info"><?php echo $row["doors_6b"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">6. Sal C</td>
<td width="50" height="25" class="info"><?php echo $row["lys_6c"]; ?></td>
<td class="info"><?php echo $row["skilt_6c"]; ?></td>
<td class="info"><?php echo $row["bt_6c"]; ?></td>
<td class="info"><?php echo $row["bs_6c"]; ?></td>
<td class="info"><?php echo $row["doors_6c"]; ?> </td>
</tr >
<tr>
<td height="25" class="sort_bar">6. Sal D</td>
<td width="50" height="25" class="info"><?php echo $row["lys_6d"]; ?></td>
<td class="info"><?php echo $row["skilt_6d"]; ?></td>
<td class="info"><?php echo $row["bt_6d"]; ?></td>
<td class="info"><?php echo $row["bs_6d"]; ?></td>
<td class="info"><?php echo $row["doors_6d"]; ?> </td>
</tr>
<tr>
<td height="25" class="grey_bar">7. Sal A</td>
<td width="50" height="25" class="grey_bar"><?php echo $row["lys_7a"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_7a"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_7a"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_7a"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_7a"]; ?> </td>
</tr>
<tr>
<td height="25" class="grey_bar">7. Sal B</td>
<td width="50" height="25" class="grey_bar"><?php echo $row["lys_7b"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_7b"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_7b"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_7b"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_7b"]; ?> </td>
</tr>
<tr>
<td height="25" class="grey_bar">7. Sal C</td>
<td width="50" height="25" class="grey_bar"><?php echo $row["lys_7c"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_7c"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_7c"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_7c"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_7c"]; ?> </td>
</tr>
<tr>
<td height="25" class="grey_bar">7. Sal D</td>
<td width="50" height="25" class="grey_bar"><?php echo $row["lys_7d"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_7d"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_7d"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_7d"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_7d"]; ?> </td>
</tr>
<tr>
<td height="20" class="split">Taget</td>
<td width="50" class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
</tr>
<tr>
<td height="14" class="sort_bar">Taget</td>
<td width="50" height="25" class="info" ><?php echo $row["lys_t"]; ?></td>
<td class="info"><?php echo $row["skilt_t"]; ?></td>
<td class="info"></td>
<td class="info"><?php echo $row["brand_s_t"]; ?></td>
<td class="info"><?php echo $row["door_t"]; ?></td>
</tr>
</table>
<br />
<?php } ?>
</body>
</html>
答案 0 :(得分:0)
如果您将查询分成几个部分,以便第一个查询从一个表中选择*并且下一个查询选择数据,则另一个表然后通过mysql_fetch_array($query1, $query2)
答案 1 :(得分:0)
按照此示例使用您的数据信任我它将起作用
// set up your query within a variable to make it easier to work with
$query = "SELECT * FROM people";
$result = mysql_query($query); //this will conect to the database and select the table to run the query on and return the values from that table.
// now we will set up a while loop to retrieve the information from the database table.
while ($person = mysql_fetch_array($result)) {
echo "<h3>". $person['name'] ."</h3>"; // this line will fetch the query result that is stored in the $person variable and find the row ['name'] and display it on screen
echo "<p>". $person['info'] ."</p>";
}
?>