Php $\u GET在此脚本中的工作原理

Php $\u GET在此脚本中的工作原理,php,Php,我正在查看此分页脚本,无法理解如何使用$\u GET。这是脚本 <?php $host = "localhost"; $user = "root"; $password = ""; $database = "world"; $db = mysql_connect($host, $user, $password); if($db) { $select_db = mysql_select_db($database);

我正在查看此分页脚本,无法理解如何使用$\u GET。这是脚本

<?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);
?>
我得到了这个

is set
so not there 

为什么$?;这样做?

字符串表示错误的内容。这显然是一个错误。如果你只是把你的琴弦弹来弹去,那就更有意义了

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/>';
}

这是因为您正在以相反的方式检查isset

if(isset($_GET['page']))
{
    echo 'not set';
在这里,您使用的是isset并检查它是否为真,即它是否为真,因此您可以在实际设置时打印not set

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

作为另一方,我想告诉您,mysql_*函数实际上已被弃用,不再被使用,因此您真的应该切换到或

尝试使用?tr=blah访问您的脚本地址栏上显示的查询字符串是什么?我不知道问题是什么。关于它是如何使用的,您到底不了解什么?您的逻辑很糟糕:如果isset$_GET['tr']{echo'not set';//但是它是set},那么在第二种情况下,如果您使用$GET而不是$\u GET
if(isset($_GET['page'])) {
    echo 'is set';
    $pageNum = $_GET['page'];
} else {
    echo 'not set';
}