-1

好的,所以这似乎很常见,但我读过的东西都没有帮助我,所以有没有人知道为什么我的变量似乎没有设置..

编辑:抱歉忘记了错误的位置,它在第 169 行,即:

if($world['$queryi'] != 0)

<?php

  if(isset($_GET['upgrade']))
  {
  if($_GET['upgrade'] > 0 && $_GET['upgrade'] < 15){ 

  $_GET['upgrade'];
  $id = $_GET['upgrade'];
  $queryi = "column_$id"; // This shows as undefined.
  $querye = "column_name_$id"; // This shows as undefined

  //When printing them out alone, they are defined, with the value i need them to be.

  if($id>=1 && $id <=14)
  {
//$world[] <- array from outside of the $_GET area (ive tried having it inside, same error)

   if($world['$queryi'] != 0)
   {

   }
   else
   {

       echo "query turned out zero";
   }

  }
  else
  {
      echo "something went wrong.";
  }
 }
 }

?>

//EDIT this is the arrayQUery which seems to be causing the problem..
$query = "SELECT * from this WHERE userid='".$user['id']."'";

$result = mysql_query($query);
$world=mysql_fetch_array($result);

有没有人有线索,怎么了?

4

2 回答 2

1

改变

$_GET['upgrade'];
$id = $_GET['upgrade'];
$queryi = "column_$id"; // This shows as undefined.
$querye = "column_name_$id"; // This shows as undefined

if(isset($_GET['upgrade'])) { 
    $id = $_GET['upgrade'];
} else {
    $id = 1;
}

$queryi = "column_" . $id; // This shows as undefined.
$querye = "column_name_" . $id; // This shows as undefined

应该做的伎俩。

还需要检查这条线是否已设置。我认为这会导致错误..:

if($world['$queryi'] != 0)

将其更改为:

if(isset($world[$queryi]) && $world[$queryi] != 0)
于 2013-10-11T06:57:30.467 回答
0

根据您的评论,我发现您的代码存在以下问题

你为什么在这一行用单引号写 $queryi if($world['$queryi'] != 0)。因为单引号意味着字符串不是名副其实的。所以你的代码意味着,搜索索引'$queryi'。但是你想要做的是,你想要搜索这个字符串 index => "column_name_$id"。因此,要么删除单引号,要么将其更改为双引号。

所以正确的代码将是

if($world[$queryi] != 0)

于 2013-10-11T07:10:19.483 回答