-4

嗨,我正在尝试从我的数据库中写入数据,而这是本应执行此操作的代码,但我得到两个“警告:mysql_fetch_array() 期望参数 1 是资源,给定的布尔值”并且不知道为什么????

$data = mysql_query("SELECT * FROM teams");
$result = mysql_fetch_array($data);


while($result = mysql_fetch_array($data)) {
    print "<b>Name:</b>" .$result['Team Name'] . " ";
}
4

2 回答 2

2

the boolean is given because your assuming the query has run ok. For some reason your query has failed maybe because you havent selected a database ?

Either way all new code shouldnt be using mysql_* instead look at mysqli_* or PDO

to see what the actual error is

if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    die($message);
}

between the query and the fetch result

于 2013-07-11T21:58:17.260 回答
-1

无论如何,您应该使用 PDO,不推荐使用 mysql_query() 和 mysql_fetch_array()。该错误通常意味着您的查询失败,根据您的问题,这可能是千千万万个不同的事情,哈哈......

于 2013-07-11T22:00:39.137 回答