Я создал каталог продуктов в PHP, я хочу, чтобы продукты отображались в виде таблицы, как в сетке, поэтому в ней есть 3 продукта в одной строке рядом, затем происходит внизу и так далее. У меня так получилось, что продукты повторяются по горизонтали, я просто не знаю, как заставить его автоматически начинать новую строку после трех продуктов ..
Вот мой код:
<?php # Script 17.5 - browse_prints.php
// This page displays the available prints (products).
// Set the page title and include the HTML header:
$page_title = 'Browse the Films';
require_once ('mysqli_connect.php');
// Default query for this page:
$q = "SELECT image_name, genre.genre_id, CONCAT_WS(' ', genre_name) AS genre, film_name, price, platform, description, film_id, image_name FROM genre, film WHERE genre.genre_id = film.genre_id AND film.platform = 'DVD' ORDER BY genre.genre_name ASC, film.film_name ASC ";
// Are we looking at a particular genre?
if (isset($_GET['gid']) && is_numeric($_GET['gid']) ) {
$gid = (int) $_GET['gid'];
if ($gid > 0) { // Overwrite the query:
$q = "SELECT image_name, genre.genre_id, CONCAT_WS(' ', genre_name) AS genre, film_name, price, description, film_id, image_name FROM genre, film WHERE genre.genre_id = film.genre_id AND film.genre_id = $gid AND film.platform = 'DVD' ORDER BY film.film_name";
}
}
// Create the table head:
echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="50%"><b>Film Name</b></td>
<td align="right" width="50%"><b>Price</b></td>
</tr><tr>';
// Display all the prints, linked to URLs:
$r = mysqli_query ($dbc, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
// Display each record:
//image
$image_name = $row['image_name'];
echo "
<td><a href=\"view_print.php?fid={$row['film_id']}\">{$row['film_name']}<br><br>
<img src=uploads/$image_name.jpg><br>
<br>£{$row['price']}</td>
";
} // End of while loop.
echo '</tr></table>';
mysqli_close($dbc);
?>