未定义的GET ID? [英] undefined GET id?
本文介绍了未定义的GET ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?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)) {
?>
我现在想要这个,当我进入我的网站(index.php)时,它应该不会出现未定义的$ _GET ["s"];
I have this now i want when i enter my site (index.php) it should not come up undefined $_GET["s"];
我该怎么做?但是我想要当您执行index.php?s时,它应该更改查询
how do i do this? but i want when you do index.php?s then it should change the query
推荐答案
使用 array_key_exists()
:>
if(isset($_GET['s'])) {
}
或
if(array_key_exists('s', $_GET)) {
}
这首先检查数组中是否确实存在一个键为s
的元素.
This first checks if there really is an element in the array with a key s
.
请勿在变量之前分配$_GET['s']
,否则您将遇到同样的问题.
Don't assign $_GET['s']
to a variable before, otherwise you will have the same issue.
我个人总是会为参数分配一个值,即使用index.php?s=1
而不是仅仅使用index.php?s
.
I personally would always assign a value to a parameter, i.e. using index.php?s=1
instead of just index.php?s
.
这篇关于未定义的GET ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文