【发布时间】:2012-06-29 12:18:13
【问题描述】:
我在这里有两个文件,在让 mysql_fetch_array 工作时遇到了一些问题。 我认为这是因为它是从另一个函数调用的?
show_results.php:
include "sql_functions.php";
function content_humanResAll (){
q_humanResAll();
while($row = mysql_fetch_array($q_humanResAll_result)){
...
sql_functions.php:
include "db_connect.php"; //connect to db
// Query for human resources
function q_humanResAll() {
$q_humanResAll = "SELECT * FROM human_resources LIMIT 0, 30";
$q_humanResAll_result = mysql_query($q_humanResAll) or die("could not query MySql");
$q_humanResAll_numRows = mysql_num_rows($q_humanResAll_result);
//return $q_humanResAll_result// tried this also, didn't work.
}
为什么我会收到错误“mysql_fetch_array() 期望参数 1 是资源,给定 null”?
顺便说一句,show_results.php 包含在 index.php 中。所以它包含很多,但这应该不是问题吧?
我也尝试过将函数 q_humanResAll() 中的变量设为全局变量,但也没有用。
如果您需要更多意见,请告诉我。
谢谢
【问题讨论】:
-
mysql_error()会告诉你问题所在。 -
感谢反对票...
-
为什么人们不赞成这个问题?不知道和不尝试(也就是无知)是有区别的。