I would like to view the products by category on the home page

I would like to view the products by category on the home page.
I have two category and products tables.
I tried to create the select categories first and after that of the products in the while.
The problem is that for each category I always get all the products.
How can I make sure that only the corresponding product is displayed for each category?
Sorry but I’m just starting out.

Scheme:

1 Category

corresponding product, corresponding product

2 Category

corresponding product

3 Category

corresponding product, corresponding product, corresponding product

Here is my query:

<?php
$sql_cat = "SELECT  category_id,category_name FROM category WHERE status='A' order by category_id ASC"; 
$result_cat = mysqli_query($conn, $sql_cat);
if (mysqli_num_rows($result_cat) > 0) {
    // output data of each row
    while($row_cat = mysqli_fetch_assoc($result_cat)) {
        $categoryid=$row_cat["category_id"];
        $category_name=$row_cat["category_name"];
        echo''.$category_name.'<br>';
        $sql = "SELECT * FROM product WHERE status='A' and category='$categoryid' Order by category ASC"; 
        $resultSet = mysqli_query($conn, $sql);
        while($row = mysqli_fetch_assoc($resultSet)) {
            $nameproduct=ucfirst(html_entity_decode($row['product_name'], ENT_QUOTES));
            echo''.$nameproduct.'';
        }   
    }   
}