开发者

undefined GET id?

开发者 https://www.devze.com 2022-12-30 07:48 出处:网络
<?php $s = $_GET[\"s\"]; if($s) { $hent_b = mysql_query(\"SELECT * FROM member_battles WHERE state = \'1\' ORDER BY id DESC LIMIT 0,200\") or die(mysql_error());
 <?php
$s = $_GET["s"];
if($s) {
$hent_b = mysql_query("SELECT * FROM member_battles WHERE state = '1' ORDER BY id DESC LIMIT 0,200") or die(mysql_error());
}else{
$hent_b = mysql_query("SELECT * FROM member_battles WHERE state = '0' ORDER BY id DESC LIMIT 0,200") or die(mysql_error());
}
while($vis = mysql_Fetch_array($hent_b)) {
 ?> 

I have this now i want when i enter my site (index.php) it should not come up undefined开发者_StackOverflow中文版 $_GET["s"];

how do i do this? but i want when you do index.php?s then it should change the query


Use isset() or array_key_exists():

if(isset($_GET['s'])) {

}

or

if(array_key_exists('s', $_GET)) {

}

This first checks if there really is an element in the array with a key s.

Don't assign $_GET['s'] to a variable before, otherwise you will have the same issue.


I personally would always assign a value to a parameter, i.e. using index.php?s=1 instead of just index.php?s.

0

精彩评论

暂无评论...
验证码 换一张
取 消