Php mysql_从另一个函数内部获取_数组结果无法工作

Php mysql_从另一个函数内部获取_数组结果无法工作,php,mysql,sql,database,Php,Mysql,Sql,Database,我这里有两个文件,在让mysql\u fetch\u数组工作时遇到了一些问题。 我想这是因为它是从另一个函数调用的 show_results.php: include "sql_functions.php"; function content_humanResAll (){ q_humanResAll(); while($row = mysql_fetch_array($q_humanResAll_result)){ ... sql_functions

我这里有两个文件,在让mysql\u fetch\u数组工作时遇到了一些问题。 我想这是因为它是从另一个函数调用的

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\u fetch\u数组期望参数1是resource,给定null

顺便说一句,show_results.php包含在index.php中。所以它包括很多,但这不应该是一个问题,对吗

我还尝试过将函数q_humanResAll中的变量设置为全局变量,但也没有成功

如果您需要更多信息,请告诉我


谢谢

您没有定义$q\u humanResAll\u结果为content\u humanResAll。所以需要从另一个函数传回,如下所示:

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)){
            ...

mysql_错误会告诉你问题出在哪里。你需要仔细阅读变量范围:thx的否决票…为什么人们否决这个问题?不知道和不尝试是有区别的,也就是无知。