Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP变量问题_Php_Variables - Fatal编程技术网

PHP变量问题

PHP变量问题,php,variables,Php,Variables,这是有效的: $customerBox = mysql_query("MY SQL STATEMENT HERE"); $boxRow = mysql_fetch_array($customerBox); $customerBox = mysql_query("MY SQL STATEMENT AGAIN"); while($item = mysql_fetch_assoc($customerBox)) { foreach ($item as $columnName =>

这是有效的:

$customerBox = mysql_query("MY SQL STATEMENT HERE");  
$boxRow = mysql_fetch_array($customerBox);  

$customerBox = mysql_query("MY SQL STATEMENT AGAIN");
while($item = mysql_fetch_assoc($customerBox)) {
      foreach ($item as $columnName => $value) {
          if (empty($value)) {
               print $columnName;
          }
      }
}
$customerBox = mysql_query("MY SQL STATEMENT HERE");  
$boxRow = mysql_fetch_array($customerBox);  

while($item = mysql_fetch_assoc($customerBox)) {
      foreach ($item as $columnName => $value) {
          if (empty($value)) {
               print $columnName;
          }
      }
}
这不是:

$customerBox = mysql_query("MY SQL STATEMENT HERE");  
$boxRow = mysql_fetch_array($customerBox);  

$customerBox = mysql_query("MY SQL STATEMENT AGAIN");
while($item = mysql_fetch_assoc($customerBox)) {
      foreach ($item as $columnName => $value) {
          if (empty($value)) {
               print $columnName;
          }
      }
}
$customerBox = mysql_query("MY SQL STATEMENT HERE");  
$boxRow = mysql_fetch_array($customerBox);  

while($item = mysql_fetch_assoc($customerBox)) {
      foreach ($item as $columnName => $value) {
          if (empty($value)) {
               print $columnName;
          }
      }
}

为什么??我想我还不明白变量是如何工作的。

这可能与mysql_fetch_array()有关,而不是与您的变量有关。试着说:

mysql_data_seek ( $customerBox , 0 );

就在while循环开始之前。我很想看到结果。

这可能与mysql_fetch_array()有关,而不是与变量有关。试着说:

mysql_data_seek ( $customerBox , 0 );

就在while循环开始之前。我很想看到结果。

问题在于,由于查询返回一行,因此没有任何内容可以提取

mysql\u fetch.*
函数获取当前行,然后将行指针前进到下一行。如果当前行不存在,则返回false。因此,在第二次调用
mysql\u fetch\u assoc
时,指针位于第二行,但该行不存在,因此不会执行循环。您有两个选择:

好:删除
while
循环,并将
foreach
更改为使用
$boxRow

foreach ($boxRow as $columnName => $value) {
    //...
}
确定:使用以下命令回放MySQL的行指针:


问题在于,由于查询返回一行,因此没有任何内容可供提取

mysql\u fetch.*
函数获取当前行,然后将行指针前进到下一行。如果当前行不存在,则返回false。因此,在第二次调用
mysql\u fetch\u assoc
时,指针位于第二行,但该行不存在,因此不会执行循环。您有两个选择:

好:删除
while
循环,并将
foreach
更改为使用
$boxRow

foreach ($boxRow as $columnName => $value) {
    //...
}
确定:使用以下命令回放MySQL的行指针:

$customerBox=mysql\u查询(“这里是我的SQL语句”)
$boxRow=mysql\u fetch\u数组($customerBox)

而($item=mysql\u fetch\u字段($customerBox)){ foreach($columnName=>$value的项目){ if(空($value)){ 打印$columnName; } } }$customerBox=mysql\u查询(“这里是我的SQL语句”)
$boxRow=mysql\u fetch\u数组($customerBox)

而($item=mysql\u fetch\u字段($customerBox)){ foreach($columnName=>$value的项目){ if(空($value)){ 打印$columnName; } }
}

查询返回的行是否超过1行?如果没有,这就是“错误”存在的原因(
$boxRow
占据第一行,并且没有更多的内容可供下一次调用获取).“此处的我的SQL语句”与“再次使用我的SQL语句”不同。duh.您正在使用什么mysql查询ingIRCMaxell-只返回1行。但我不确定我是否理解。不管从$customerBox中提取什么,它都等于相同的东西吗?rajmohan-SELECT*from框,其中customer\u id=“$logOptions\u id”查询返回的行是否多于一行?如果没有,这就是“错误”存在的原因(
$boxRow
占据第一行,并且没有更多的内容可供下一次调用获取).“此处的我的SQL语句”与“再次使用我的SQL语句”不同。duh.您正在使用什么mysql查询ingIRCMaxell-只返回1行。但我不确定我是否理解。难道$customerBox不等于相同的东西,不管从中获取的是什么吗?rajmohan-从customer_id='$logOptions_id'+1的框中选择*,因为你确实击败了我(即使你在我发布我的答案后立即删除了你的答案)…+1因为你击败了我(即使你在我发布我的答案后立即删除了你的答案)。。。