2013-09-23 58 views
0

我有一些問題,並在表中插入數據。數據庫和表

我想從2個不同的表中得到2行信息旁邊eachother。但我無法弄清楚爲每個表格分出兩行。下面你可以找到我的代碼:

<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

,你的問題是什麼?另外:mysql_ *函數被棄用,請使用mysqli_ *或PDO – NDM

+1

那麼,我現在得到1行。他們都在彼此之下。我想要2個不同的行。 1用於WallTiles,1用於FloorTiles – Bart

+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    
} 
?> 
+0

那麼重點是我想要2行。 1用於Floopoliles 1用於壓裂。如果我使用我們的代碼,我會得到1行,其中所有的瓷磚。 – Bart

+0

不,它會爲數據庫中的每一行生成一個HTML行。 – NDM

+0

嗯,我不允許在數據庫中改變任何東西,所以我不能編輯這些表格 – Bart