Hi.
I just wrote the below code to run and show results from a database. The results show one above the other down the left side of the page. I would like them to show side by side , 3 or 4 then start a new row , until all results have been shown. Is this possible with CSS or do i have to go learn how to do it in php. I am able to style the results into boxes , but as i see it the style applies to all results rather than each result so cant see a way to seperate each box. Been wrestilng with this for ages.
Thanks amd appreciate any help.
Search.php
if (isset ($_POST['search'])) {
$search = $_POST['search'];
$search = "%" . $search . "%"; // MySQL wildcard % either side of search to get partially matching results
// No wildcard if you want results to match fully
}
$stmt = $conn->prepare("SELECT * FROM whisky_results WHERE name LIKE :name ORDER BY name ASC"); // Use = instead of LIKE for full matching
$stmt->bindParam(':name', $search);
$stmt->execute();
$count = $stmt->rowCount(); // Added to count no. of results returned
if ($count >= 1) { // Only displays results if $count is 1 or more
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<br>";
echo "<div class=\"results\">";
echo "<div class=\"result_name\">";
echo "<b>Whisky Name:</b><br>";
echo $row['name'];
echo "</div>";
//echo "<div class= \"result_description\">";
//echo "Whisky Description: ";
//echo $row['description'];
//echo "</div>";
echo "<div class= \"result_highprice\">";
echo "Highest Price Paid: £";
echo $row['highest_price'];
echo "</div>";
echo "<div class= \"result_lowprice\">";
echo "Lowest Price Paid: £";
echo $row['lowest_price'];
echo "</div>";
echo "<div class= \"average_price\">";
echo "Average Price Paid: £";
echo $row['average_price'];
echo "</div>";
echo "<div class= \"last_price\">";
echo "Last Price Paid: £";
echo $row['last_price'];
echo "</div>";
echo "<div class= \"last_date\">";
echo "Last date sold: ";
echo $row['last_date'];
echo "</div>";
echo "</div>";
echo "<br>";
}
} else {
echo " Sorry no records were found";
}