I'm redesigning my website, and I want to display records in a table 4 rows across and down however many rows it needs.
I've got this script which I've been toying around with for hours, but I'm not getting the desired result. In fact, it's just listing row after row.
<div class="row">
<div class="col-3 col-12-medium">
<?php
$finditems="Coffee Mugs - Ceramic";
$servername = '';
$username = '';
$password = '';
$dbname = '';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}$sql = "SELECT * FROM inventory WHERE product_subcategory LIKE '$finditems'
AND(product_active='Y' OR product_active='C' OR product_active='O') AND
web_sale<>'N' ORDER BY product_name ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<div class=''col-3 col-12-medium'>". $row["product_name"]. " " .
$row["product_code"]. " $" . $row["product_p1"]. "<br><img
src='products/".$row['product_code'].".jpg' width='100' height='100'>
</div>";
}
} else {
echo "0 results";
}
?>
</div><div>
Some of the results may find only 2 items, others might show 10 (depending on the search term). So when there is multiple, it shows the next item to the right, until the row of 4 is filled, then it goes to the next row. I know i'm missing something for it to calculate it, but I just ain't finding it.
Your help will be appreciated.