使用php自动增加LIMIT

I want my limit to be auto incremented whenever the user clicks submit, so the value will be updated, and the user will see the previous messages that he sent, Here is my code:

if(isset($_POST['text']))
{
$counter =1;
$message = mysqli_real_escape_string($con,$_POST['text']);
if(!empty($message))
    {
        $id = $_SESSION['id'];
        $time = time();
        $date = date('Y-m-d H:i:s', $time);
        $query = "INSERT INTO tbl_chat(time_sent,message_text,users_id) VALUES('$date','$message','$id')";
        mysqli_query($con,$query);
        $query = "SELECT TIME(time_sent)AS time_sent, i.users_fname, c.message_text FROM tbl_usersinfo AS i INNER JOIN tbl_chat AS c ON 
                                i.users_id = c.users_id ORDER BY c.time_sent DESC LIMIT $counter";
        $counter++;
        if($run_query = mysqli_query($con,$query))
        {
            while($row = mysqli_fetch_assoc($run_query))
            {
            $time_sent = $row['time_sent'];
            $users_fname = $row['users_fname'];
            $message_text = $row['message_text'];
            echo '['.$time_sent.']'.$users_fname.': '.$message_text.'<br/>';
            }
        }
    }
}

The problem with my code is that the sql only read the value of counter as 1, so it didn't echo the previous messages that the user sent. Is it possible to auto increment limit with php?

Every time the page will be reloaded the value of the $counter variable will be assigned to 1. You can use either $_SESSION or $_COOKIE variable to store the counter and increment that $_SESSION/$_COOKIE variable.

N.B: before setting the $_SESSION/$_COOKIE variable check whether it is already set or not. if already set dont set it again.