2012-06-29 4 views
-4

여기에 두 개의 파일이 있는데 mysql_fetch_array가 작동하는 데 문제가 있습니다. 다른 함수에서 호출 되었기 때문에 이것이라고 생각하십니까?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_ASSOC가() 매개 변수 1가 null 주어진 자원이 될 것으로 기대"어떻게해야합니까?

Btw, show_results.php는 index.php에 포함되어 있습니다. 그래서 많은 것이 포함되지만 문제가되지 않아야합니까?

또한 q_humanResAll() 함수 내에서 변수를 만들려고했으나 작동하지 않았습니다.

추가 입력이 필요한 경우 알려주십시오.

감사

+0

mysql_error()는 문제의 원인을 알려줍니다. –

+0

가변 범위에서 읽어야합니다. http://php.net/manual/en/language.variables.scope.php – jeroen

+0

downvotes에 대한 thx ... – user1214823

답변

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)){ 
      ... 
관련 문제