我在表中遇到了一些问题,并在其中插入数据。
我想从2个不同的表中获取彼此相邻的2行信息。但是我无法弄明白每张桌子都有两个分开的行。您可以在下面找到我的代码:
<form action="Stap5.php" method="POST">
<table border = '1'>
<tr>
<td>Vloerbetegeling</td>
<td>Wandbetegeling</td>
</tr>
<?php
$query="select * from vloertegel";
$result=mysql_query($query);
$query2="select * from wandtegel";
$result2=mysql_query($query2);
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td><input type='radio' name='FloorTiles' value='<?php echo $row['Naam'] ?>' checked/><?php echo $row['Naam'] ?> <br/>
<img src='<?php echo $row['ImagePath'] ?>' width='200' height='200' /> </td>
</tr>
<?php
}
while($row2=mysql_fetch_array($result2))
{
?>
<tr>
<td><input type='radio' name='WallTiles' value='<?php echo $row2['Naam'] ?>'checked/> <?php echo $row2['Naam'] ?> <br/>
<img src='<?php echo $row2['ImagePath'] ?>' width='200' height='200'/></td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="Stap5Submit" value="Volgende"/><br />
</form>
while循环使得我的结果变得更难。
答案 0 :(得分:1)
将所有瓷砖放在一张桌子中会不会更好?
table tiles: (id, name, imagePath, tileType);
// to fetch all tiles:
SELECT * FROM tiles ORDER BY tileType
然后你只需要做1个查询和1个循环
<?php
while($row=mysql_fetch_array($result)) {
?>
<tr>
<td>
<input type="radio" name="<?php
($row["tileType"] == 'xxx') ? 'FloorTiles': 'WallTiles'; ?>" ?>
value="<?php echo $row['name'] ?>" checked/><?php
echo $row['name']
?> <br/>
<img src="<?php echo $row['imagePath'] ?>" width="200" height="200" />
</td>
</tr>
<?php
}
?>