$ _GET如何在此脚本中工作[关闭]

I am going through this pagination script and i cannot understand how $_GET is being used.This is the script

<?php
$host = "localhost";
    $user = "root";
    $password = "";
    $database = "world";

    $db = mysql_connect($host, $user, $password);
    if($db)
    {
        $select_db = mysql_select_db($database);
        if(!$select_db)
        {
            echo 'Database Error:'. mysql_error();
        }
    }else
    {
        echo 'Connection Error:'. mysql_error();
    }
$rowsPerPage = 15;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
echo 'not set';
$pageNum = $_GET['page'];
}
else{echo 'is set';}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$query = "select * from city" .
" LIMIT $offset, $rowsPerPage";
//print $query;
$result=mysql_query($query);
?>

I named the script p.php.

This script works although the script do not have a query string that has ?page=n

I tried executing this script named tr.php

if(isset($_GET['tr']))
{
echo "not set <br/>";
}
else{echo 'is set <br/>'; }

if(empty($_GET['tr'])){
echo 'so not there <br/>';
}

and i got this

is set
so not there 

Why is $_GET; acting like this?.

This is because you are checking your isset() in the opposite way

if(isset($_GET['page']))
{
    echo 'not set';

Here you are using isset and checking if it is true, which is it, so you print not set while it is actually set

if(isset($_GET['page'])) {
    echo 'is set';
    $pageNum = $_GET['page'];
} else {
    echo 'not set';
}

As side not i'd like to tell you that mysql_* function are actually deprecated and no longer manteined so you really should switch either to mysqli or PDO

The strings says the wrong things. It is clearly a mistake. It makes a whole lot more sense if you just flip your strings around.

if(isset($_GET['tr']))   // This means it IS set...
{
    echo "IS set <br/>";    // ...thus, we change this....
}
else
{
    echo 'is NOT set <br/>';    // ... and this.
}

if(empty($GET['tr'])){
    echo 'so not there <br/>';
}