0

テーブルとそのテーブルへのデータの挿入に問題があります。

2 つの異なるテーブルから 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 ループにより、結果を取得するのが難しくなっています。

4

1 に答える 1

1

すべてのタイルを 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            
}
?>
于 2013-09-23T08:07:30.200 に答える