我这里有两个文件,并且在使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()全局内部创建变量,但也没有。
如果您需要更多输入,请告诉我。
由于
答案 0 :(得分:1)
您未在content_humanResAll中定义$ q_humanResAll_result。所以你需要从其他函数传回来,如下所示:
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;
}
function content_humanResAll (){
$q_humanResAll_result = q_humanResAll();
while($row = mysql_fetch_array($q_humanResAll_result)){
...