Php 多个$u GET函数不';行不通

Php 多个$u GET函数不';行不通,php,html,get,Php,Html,Get,我一直在设计一些网站。我一直在尝试使用多个if(isset($_GET['type'])=='page'){}等函数。他们好像没用,有人能给我点化一下吗 <?php if(isset($_GET['type']) == 'all') { // View All Pages Title echo '<h3>View All Pages</h3>'; if($control1 == 'all') { ec

我一直在设计一些网站。我一直在尝试使用多个if(isset($_GET['type'])=='page'){}等函数。他们好像没用,有人能给我点化一下吗

<?php
    if(isset($_GET['type']) == 'all') {
    // View All Pages Title
    echo '<h3>View All Pages</h3>';

        if($control1 == 'all') {
            echo '<table width="100%" border="0">';
            echo '<tr>';
            echo '<th scope="col">Page Name</th>';
            echo '<th scope="col">Time Created</th>';
            echo '<th scope="col">View</th>';
            echo '<th scope="col">Edit</th>';
            echo '<th scope="col">Delete</th>';
            echo '</tr>';                 
            $qry=mysql_query("SELECT * FROM page", $con);
            if(!$qry) {
                die("Query Failed: ". mysql_error());
        }
        while($row=mysql_fetch_array($qry)) {
            echo '<tr>';
            echo '<td height="38">'.$row['page_title'].'</td>';
            echo '<td>'.$row['page_updated'].'</td>';
            echo '<td><a href="page.php?view=page&page='.$row['page_link'].'">View</a></td>';
            echo '<td><a href="page.php?edit='.$row['page_link'].'">Edit</td>';
            echo '<td><a href="page.php?delete='.$row['id'].'">Delete</td>';
            echo '</tr>';
        }     
        echo '</table>';
    }
    else {
        echo "<p>You can't view all the pages. Your Account does not hold the correct priorirty</p>";   
    }
}
elseif(isset($_GET['type']) == 'add') {
    // Add New Page Title
    echo '<h3>Add New Page</h3>';
        if($control1 == 'all') {
            echo '<p><a href="pages.php?type=add&add=control" target="new">Click Here to add a new page</a></p>';
    }
    else {
        echo "<p>You can't add new pages. Your Account does not hold the correct priority.</p>";
    }
}
elseif(isset($_GET['type']) == 'edit') {
    // Edit Pages Title
    echo '<h3>Edit a Page</h3>';
        if($control1 == 'all') {
            echo '<table width="100%" border="0">';
            echo '<tr>';
            echo '<th scope="col">Page Name</th>';
            echo '<th scope="col">Edit</th>';
            echo '</tr>';
            $qry=mysql_query("SELECT * FROM page", $con);
                if(!$qry) {
                    die("Query Failed: ". mysql_error());
            }
            while($row=mysql_fetch_array($qry)) {
                echo '<tr>';
                echo '<td height="38">'.$row['page_title'].'</td>';
                echo '<td><a href="page.php?edit='.$row['page_link'].'">Edit</td>';
                echo '</tr>';
            }
            echo '</table>';
        }
        else {
            echo "<p>You can't edit any pages. Your Account does not hold the correct priority </p>";
        }
    }
?>
必须是这样的

if(isset($_GET['type']) && $_GET['type'] == 'page')
isset($\u-GET['type'])
返回一个布尔值,因此如果将该布尔值与任何不相同的布尔值(
isset($\u-GET['type'])=='all'
)进行比较,它将返回false

你应该这样做

if ( isset($_GET['type']) && $_GET['type'] == 'all' ) { // code }

isset
返回布尔值:true或false。因此,您的代码:

if(isset($_GET['type']) == 'page')
不行。您可以这样更改它:

if(isset($_GET['type']) and $_GET['type'] == 'page')

问题是
isset()
函数只返回
TRUE
FALSE
,您将其与字符串进行比较。就这样用吧:

if (isset($_GET['type']) {
   if ($_GET['type'] == 'page') {
      //...
   } elseif($_GET['type'] == 'add') {
      //and so on...
   }
}
最好将
isset
测试放在开头,这样您就不会在每个
if
语句中检查它。

在我看来,isset()返回一个布尔值(真/假),您将其与“all”、“add”等进行比较。那不是你想要的

你可以做:

if (isset($_GET['type']) && $_GET['type'] == "all") {
    #your code here
}

谢谢,我从未意识到。所以我应该用我所有的$GET函数来做这件事?其他人都这么说:如果($GET['type'])和$GET['type']='page'),那么我不确定你的答案是否正确?是的,它是正确的:)如果
$GET['type']='add'
没有设置,那么检查
$GET['type']
是没有意义的。但是,如果您在每个
if
语句中检查它,您将重复自己的操作,但您确实不需要这样做,您可以检查
$\u GET
是否只设置了一次。谢谢Peter,我做到了,而且它还挺管用的,我可能没有正确地实现它。