SQL行选择的比较不起作用?

This is the code that is not working:

        $query = "SELECT * FROM $table WHERE text_id > '$last_id'"; //SELECT NEW MESSAGES
        $result = mysqli_query($connection,$query);

        if ($result && mysqli_num_rows($result) > 0)
        {
          //THIS SHOULD NOT BE RUNNING
        }

I've verified over and over in phpMyAdmin and the text_id in the table and $last_id are both the integer value '1'. That being said, the condition equates to true every time the code runs.

Am I messing this code up, or is my thinking improper?

Here is entire script:

<?php
    session_start();
    $alias = $_SESSION['username'];

    $host = 'localhost';
    $user = '*';
    $pass = '*';
    $database = 'vethergen_db_accounts';
    $table = 'table_messages';
    $last_id_table = 'table_chat_sync';
    $connection = mysqli_connect($host, $user, $pass) or die ("Unable to connect!");
    mysqli_select_db($connection,$database) or die ("Unable to select database!");

    $last_id_query = "SELECT alias FROM $last_id_table WHERE alias = '$alias'";
    $last_id_result = mysqli_query($connection,$last_id_query);
    $last_id_rows = mysqli_fetch_array($last_id_result);

    if ($last_id_rows['alias'] === $alias)
    {
        $last_id = $last_id_rows['last_id'];
        $query = "SELECT * FROM $table WHERE text_id > '$last_id'"; //SELECT NEW MESSAGES
        $result = mysqli_query($connection,$query);

        if ($result && mysqli_num_rows($result) > 0)
        {
            while($row = mysqli_fetch_array($result))
            {
                if ($row['alias'] === "Vether")
                {
                    echo '<p id = "chat_text">'.'<b>'.$row['alias'].'</b>'.': '.$row['text']."</p>";
                    echo '<p id = "time_stamp">'.$row['time'].'</p>';
                    echo '<p id = "chat_number">'.$row['text_id'].'</p>';
                }
                else
                {
                    echo '<p id = "chat_text">'.'<b class = "bold_green">'.$row['alias'].'</b>'.': '.$row['text']."</p>";
                    echo '<p id = "time_stamp">'.$row['time'].'</p>';
                    echo '<p id = "chat_number">'.$row['text_id'].'</p>';
                }
                echo '<hr class = "chat_line"></hr>';
                $last_row_id = $row['text_id'];
            }
        }


        //UPDATE LAST SYNC ID
        $update_query = "UPDATE $last_id_table SET last_id = '$last_row_id' WHERE alias = '$alias'";
        mysqli_query($connection,$update_query);
    }
    else
    {
        $update_query = "INSERT INTO $last_id_table (alias, last_id) VALUES('$alias','-1')";
        mysqli_query($connection,$update_query);
    }
?>

You should change ;

WHERE text_id > '$last_id'

to

WHERE text_id > $last_id

text_id column is integer and can't be compared like string.