dsqpx86002 2013-06-13 08:10
浏览 9
已采纳

$ _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?.

  • 写回答

2条回答 默认 最新

  • dongxiz5342 2013-06-13 08:15
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测