這是我迄今爲止的輸出代碼。正如預期的那樣,它目前顯示彼此之下的所有內容。格式化PHP/HTML中的MySQL查詢
<table id="dslrTable">
<?php
while($row = mysqli_fetch_assoc($result)) { ?>
<?php echo "<tr><td> <a href=model.php?id=" . $row["ID"] . ">" . "<img src=images/" . $row["Image URL"] . " </a></td></tr>"; ?>
<?php echo "<tr><td> <a href=model.php?id=" . $row["ID"] . ">" . $row["Make"] . " " . $row["Model"] . " </a></td><tr>"; ?>
<?php echo "<tr><td> <a href=#.php>[add to compare] </a> </td></tr>"; ?>
<?php } ?>
</table>
我想實現的是在數據庫中每行三個tr。圖片,製作/模型,然後是超鏈接。 4「結果」後,然後做一個新的tr。像這樣的東西。
<table>
<tr>
<td>Image 1</td>
<td>Image 2</td>
<td>Image 3</td>
<td>Image 4</td>
</tr>
<tr>
<td>Make and Model 1</td>
<td>Make and Model 2</td>
<td>Make and Model 3</td>
<td>Make and Model 4</td>
</tr>
<tr>
<td>Hyperlink 1</td>
<td>Hyperlink 2</td>
<td>Hyperlink 3</td>
<td>Hyperlink 4</td>
</tr>
<tr>
<td>Image 5</td>
<td>Image 6</td>
<td>Image 7</td>
<td>Image 8</td>
</tr>
<tr>
<td>Make and Model 5</td>
<td>Make and Model 6</td>
<td>Make and Model 7</td>
<td>Make and Model 8</td>
</tr>
<tr>
<td>Hyperlink 5</td>
<td>Hyperlink 6</td>
<td>Hyperlink 7</td>
<td>Hyperlink 8</td>
</tr>
</table>
併爲此繼續下去,直到我的while循環停止。我知道我需要使用模塊除了計數器變量,但我不能讓它工作。
任何幫助表示讚賞,謝謝。
儘管此代碼可以回答這個問題,提供有關爲什麼和/或如何代碼回答了這個問題提高了其長期價值的其他方面。 –