mysql_fetch_row无效

时间:2013-09-19 00:02:05

标签: php mysql

我有一个查询数据库并计算其中行数的函数。

if($action=='shipping_list')
{ 
    $row;
    $shipping=shipping_list();
    $numrow=$r[0];
    $row=mysql_fetch_row($paging);
    include('shipping_list.php');
}

function shipping_list()
{
    global $MEMS;
    global $row;
    $query = "SELECT * FROM Inventory
                      WHERE Yield >=330 AND 
                            (Q = 'Pass' OR Q = 'No Q') AND 
                            shipdate = ' '
                   ORDER BY Wafer ASC, RC ASC";
    $shipping = $MEMS -> query($query);

    $query = "SELECT COUNT(*) Inventory
               WHERE Yield >=330 AND 
                     (Q = 'Pass' OR Q = 'No Q') AND 
                     shipdate = ' '";
    $paging = $MEMS -> query($query);
    return $shipping;
}

基本上,它调用该函数,该函数具有一个SQL命令,用于计算返回的查询数。然后代码使用MySQL获取行获取行。

但是$row继续NULL,这里有人知道我做错了吗?

1 个答案:

答案 0 :(得分:0)

  • 我认为函数shipping_list()位于shipping_list.php文件中。

如果你想调用一个函数,首先不要在调用之后包含.php

if($action=='shipping_list'){ 

   $shipping=shipping_list();
   $numrow=$r[0];
   $row=mysql_fetch_row($paging);
   include('shipping_list.php');
}

正确

if($action=='shipping_list'){ 
   include('shipping_list.php');
   $shipping=shipping_list();
   $numrow=$r[0];
   $row=mysql_fetch_row($paging);
}
  • 如果函数shipping_list()与代码的其余部分位于同一文件中。*

您无法使用$paging,因为您没有返回$paging只返回$shipping

$paging超出范围,只能在函数shipping_list()中访问。

 $row=mysql_fetch_row($paging);

shipping_list.php

function shipping_list(){
....
$paging = $MEMS -> query($query);
return $shipping;
}

<强>更新

自己测试包含在错误位置的影响。

setHello.php

<?php
 function setHello() {
  echo "Hello World<br />";
 }
?>

testInclude.php

<?php
if (function_exists('setHello')) {
  print "setHello<br /> defined\n<br />";
} else {
  print "setHello<br /> not defined\n<br />";
} 

 setHello();
 include "SetHellop.php";

 if (function_exists('setHello')) {
  print "setHello<br /> defined\n<br />";
} else {
  print "setHello<br /> not defined\n<br />";
}

?>

您将不会收到错误,只会输出:

setHello
not defined

将testInclude.php更改为

testInclude.php

<?php
if (function_exists('setHello')) {
  print "setHello<br /> defined\n<br />";
} else {
  print "setHello<br /> not defined\n<br />";
} 
 include "SetHellop.php"; 
 setHello();

 if (function_exists('setHello')) {
  print "setHello<br /> defined\n<br />";
} else {
  print "setHello<br /> not defined\n<br />";
}
?>

你得到输出。

setHello
not defined 
Hello World
setHello
defined