I've got some issues with a table and inserting data in it.
I want to get 2 rows of information next to eachother from 2 different tables. ButI can't figure it out to get 2 seperated rows for each table. Below you can find my code:
<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>
The while loops are making it harder to get my result.
Wouldn't it be nicer to have all tiles in 1 table?
table tiles: (id, name, imagePath, tileType);
// to fetch all tiles:
SELECT * FROM tiles ORDER BY tileType
Then you only have to do 1 query, and 1 loop
<?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
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.