如果没有与该类别相关的新闻,如何避免显示该类别的标题?

In the design that I am implemented, is to have an order of each news by their categories.

When there are news related to that category, the results are displayed correctly without any problem

Example:

 PREMIER LEAGUE
 Lorem ipsum dolor sit amet, consectetur adipiscing elit 1
 Lorem ipsum dolor sit amet, consectetur adipiscing elit 2

 CUP AMERICA
 Lorem ipsum dolor sit amet, consectetur adipiscing elit 3
 Lorem ipsum dolor sit amet, consectetur adipiscing elit 4

My little problem in the code of the query, is that when there is no news for a category, the title of that category is displayed, resulting in the following:

PREMIER LEAGUE
Lorem ipsum dolor sit amet, consectetur adipiscing elit 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit 2

CUP AMERICA

So my question is, how can I avoid showing the category title when there is no news related to that category?

In order to have, a consequent result:

PREMIER LEAGUE
Lorem ipsum dolor sit amet, consectetur adipiscing elit 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit 2

CUP AMERICA

My code

$stmtcategory = $con->prepare("SELECT id_category,title_category FROM category WHERE active=?");
$stmtcategory->bind_param("i",$active);
$active = "1";
$stmtcategory->execute();
$stmtcategory->store_result();

if ($stmtcategory->num_rows>0) {
    $stmtcategory->bind_result($id_category, $title_category);
    while ($stmtcategory->fetch()) {
        echo '<div class="date-text">
            <h4>'.$title_category.'</h4>
            <ul>';

        $stmt = $con->prepare("SELECT id_one_more_news,cover_page,title,description,detail,url,date_post FROM one_more_news WHERE id_category=? order by id_one_more_news ASC LIMIT 2");
        $stmt->bind_param("i",$id_category);
        $stmt->execute();
        $stmt->store_result();

        if ($stmt->num_rows>0) {
            $stmt->bind_result($id_one_more_news, $cover_page, $title, $description, $detail, $url, $date_post);
            while ($stmt->fetch()) {
                echo '<li>'.$title.'</li>';
            }

            echo '</ul>';
            echo '</div>';
        } else {
            //echo "<span>There is no news</span>";
            echo '</ul>';
            echo '</div>';
        }
    }
} else {
    echo "There is no news";
}

Additional Information

enter image description here

There is little change in your code. First, query the news according to the category. Second, check if there is the news or not. If not, don't show the category.

$stmtcategory = $con->prepare("SELECT id_category,title_category FROM category WHERE active=?");
$stmtcategory->bind_param("i",$active);
$active = "1";
$stmtcategory->execute();
$stmtcategory->store_result();

if ($stmtcategory->num_rows>0) {
    $stmtcategory->bind_result($id_category, $title_category);
    while ($stmtcategory->fetch()) {    
        $stmt = $con->prepare("SELECT id_one_more_news,cover_page,title,description,detail,url,date_post FROM one_more_news WHERE id_category=? order by id_one_more_news ASC LIMIT 2");
        $stmt->bind_param("i",$id_category);
        $stmt->execute();
        $stmt->store_result();

        if ($stmt->num_rows>0) {
            echo '<div class="date-text">
                <h4>'.$title_category.'</h4>
                <ul>';
            $stmt->bind_result($id_one_more_news, $cover_page, $title, $description, $detail, $url, $date_post);
            while ($stmt->fetch()) {
                echo '<li>'.$title.'</li>';
            }

            echo '</ul>';
            echo '</div>';
        }
    }
} else {
    echo "There is no news";
}