Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数中的php mysql查询不工作_Php_Mysql_Function - Fatal编程技术网

函数中的php mysql查询不工作

函数中的php mysql查询不工作,php,mysql,function,Php,Mysql,Function,我有一个mysql查询,它返回多列中的值之和。查询是正确的,当我将其包含在主页中时,一切都正常工作。但当我在另一个函数中做一个函数时,问题就开始了 页面包括那边的查询,并返回总和,然后在主页上打印它,因为它不起作用 以下是主页面调用: require('totals.php'); $res_easyhint_total=easyhint_totals($currentpid); print $res_easyhint_total; //The above is contained in a w

我有一个mysql查询,它返回多列中的值之和。查询是正确的,当我将其包含在主页中时,一切都正常工作。但当我在另一个函数中做一个函数时,问题就开始了 页面包括那边的查询,并返回总和,然后在主页上打印它,因为它不起作用

以下是主页面调用:

require('totals.php');
$res_easyhint_total=easyhint_totals($currentpid);

print $res_easyhint_total;
//The above is contained in a while loop and current pid gets updated each time.
功能页:

function easyhint_totals($currentpid){
require('connect.php');
$sql_easyhint_total = "SELECT sum(Coffee+Gift+Cools+Affection+Patience+Anger+EHignore) from whyangry.posts where Pid=$currentpid";
$res_easyhint_total=mysql_query($sql_easyhint_total,$con);
$res_easyhint_total=mysql_fetch_array($res_easyhint_total);
$res_easyhint_total=$res_easyhint_total[0];
return $res_easyhint_total;
}

我不知道错误是什么,请帮助。

您是否在connect.php中定义了任何函数?如果没有,请尝试添加以下内容:

$res_easyhint_total=mysql_query($sql_easyhint_total,$con);

if (mysql_errno() != 0) {
    echo mysql_error();
}

$res_easyhint_total=mysql_fetch_array($res_easyhint_total);

你检查过新页面的结果了吗?我的意思是说,如果您试图打印新页面本身的结果,就像您尝试从主页打印结果一样。然后还有一件事需要说明,两个文件的路径都包括在内。尝试将任何其他变量从新页面传递到主页面,并检查新文件是否正确包含


如果您能够从主页上的新页面访问其他变量,而它只是不从函数返回结果。尝试在主页上也包含connect.php并检查它

您以前包含过文件“connect.php”吗


检查您的连接字符串是否返回正确的链接标识符,并检查日志是否存在来自mysql的任何错误或警告,如警告:mysql_query():[2002]没有此类文件或目录(尝试通过unix:///var/run/mysql/mysql.sock). 在这种情况下,请尝试设置正确的套接字文件位置。

定义不工作。。。它会抛出错误吗?意外的结果?如果是,结果/预期结果是什么?它没有给出任何结果。而且while循环也被卡住了。首先,你不应该在函数中包含文件。。。或者在循环中,如果这是您正在做的。@PratikMehta while循环在哪里?我尝试在函数外部包含连接文件,但仍然不起作用,while循环没有显示在这里,但在实际代码中,因为它有太多的函数。剩下的一切都很好,只需要知道为什么函数中包含的内容没有显示结果
if(!@include_once('connect.php')) {
     // include connect.php
}