PHP - 获取数据时的标题重定向

I want my page to automatically redirect to another page when the data is fetch on the page so how can I do it ? i have this code

here is my code here is where the data is fetched but once it fetch i want to redirect it automatically.

<div>
    <?php
    $data = mysqli_query($con,"SELECT * FROM announcement");
    $count = mysqli_num_rows($data);

    if ($count != 0) {
        //IVE ASSUMED THAT THIS WILL WORK BUT IT DIDNT 
        header("location:../addRedirect.php");

        while($row = mysqli_fetch_array($data)) { 
            echo '<div id="myModal" class="modal" style="position:fixed;  display: none; padding-top: 100px; 
            left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.9); ">
                <div class="container" style="width: 100%">
                    <div class="card col-12" style="background-color: red; color: white;">
                        <div class="card-header">
                            <p><h3 class="text-center">Announcement</h3></p>
                        </div>
                        <div class="card-body text-center">
                            <h5>'.$row['additional_info'].'</h5>
                            <p>Please click refresh button to resume after the announcement</p>
                        </div>
                    </div>
                </div>
                <img class="modal-content" id="img01">
            </div>';
            $dataid = $row['id'];
        }
    }
    ?>
</div>

and on my second page i want to redirect it back.. so what i have is an auto refresh when im just fetching data.. thanks guide me pls this is a huge help for me as a starter of php and codings thanks.

<?php     
header("location:../home.php");   
?>

You can refresh your page using javascript instead of PHP, if the headers are already set.

<div>
    <?php
    $data = mysqli_query($con,"SELECT * FROM announcement");
    $count = mysqli_num_rows($data);

    if ($count != 0) {
        echo "<script>setTimeout(\"location.reload()\",1000);</script>";
        // Other stuff ...
    }
    ?>
</div>

If you want to navigate to an other page you can do this:

<div>
    <?php
    $data = mysqli_query($con,"SELECT * FROM announcement");
    $count = mysqli_num_rows($data);

    if ($count != 0) {
        echo "<script>setTimeout(\"location.href = '../addRedirect.php';\",1000);</script>";
        // Other stuff ...            
    }
    ?>
</div>

Both examples have a delay of 1 second (1000 milliseconds)