我经常碰到这样问题,如题
报错信息是:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\frombphp.php on line 38一下是我的代码:
<?php
$netID = $_POST['netID'];//connect database:
$con = mysql_connect("localhost","root","199026");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
else {
echo "connect database successful";
echo "<br />";
}
$dbselect = mysql_select_db("andy", $con);
if ( !$dbselect ) {
echo "select db fail";
}$sql = "select * from Module where mCode = (select mCode from Registration where netId = '$netID';";
$result = mysql_query($sql);
  echo "<table border='1'>
<tr>
<th>mCode</th>
<th>mTitle</th>
<th>mDescription</th>
<th>mLeader</th>
<th>credit</th>
<th>fee</th>
</tr>";
     while ( $row = mysql_fetch_array($result,$con) ) {//这里报错
   echo "<tr>";
               echo "<td>" . $row[0] . "</td>";
               echo "<td>" . $row[1] . "</td>";
   echo "<td>" . $row[2] . "</td>";
   echo "<td>" . $row[3] . "</td>";
   echo "<td>" . $row[4] . "</td>";
   echo "<td>" . $row[5] . "</td>";
               echo "</tr>";
  
  }    
  echo "</table>";?>

解决方案 »

  1.   

    while ( $row = mysql_fetch_array($result) ) {}
      

  2.   

    mysql_fetch_array() 中可选的第二个参数 result_type 是一个常量,可以接受以下值:MYSQL_ASSOC,MYSQL_NUM 和 MYSQL_BOTH
    用 mysql_fetch_array() 并不明显 比用 mysql_fetch_row() 慢
    看看手册吧
      

  3.   

    $sql = "select * from Module where mCode = (select mCode from Registration where netId = '$netID';";
    $result = mysql_query($sql);你提交的$sql命令返回结果有问题, 先判断下$result是否有效就可以啦
      

  4.   

    $sql = "select * from Module where mCode = (select mCode from Registration where netId = $netID)";
    $result = mysql_query($sql);
    if ( !$result ) {
    echo "<script language=javascript>alert('sql error!');history.back();</script>";
    }
    现在改成这样了,提示sql错,有错吗?sql?
      

  5.   

    $sql = "select * from Module where mCode = (select mCode from Registration where netId = '$netID';"; ????????????按语法形式,怎么也得 
    select * from Module where mCode = (select mCode from Registration where netId = '$netID'当然 
    select * from Module where mCode = (select mCode from Registration where netId = $netID)
    也是错的,因为子查询返回的是集合,如何能与单值数据比较呢
    select * from Module where mCode in (select mCode from Registration where netId = $netID)
      

  6.   

    谢谢大家,我是新手,感谢大家耐心解答!
    我在学校学习时候是用orcle的sql,似乎有语法不一致的时候
    比如大家说我错的这个
    select * from Module where mCode = (select mCode from Registration where netId = '$netID')
    我在orcle就是对的。
    废话不多说,我接着学基础!