I have a mysql query that returns sum of values in multiple columns. The query is right and everything is working normally when i include it in the main page. But the problem starts when i make a function in another page include the query over there and return the sum and print it in main page its not working .
Below is the main page call :
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 page:
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;
}
I dont get what the error is please help.
Do you define any functions in connect.php? If not try adding this:
$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);
Have you checked the result from the new page there itself? I mean to say if you tried to print the result from the new page itself as like you tried from main page. Then one more thing need to concetrate that, the path of both file while including. Try to pass any other variable from the new page to main page and check if the new file included properly.
If you are able to access other variable from new page on main page and its just not returning the result from the function. Try to include connect.php on main page also and check it.
Have you included the file "connect.php" before?
if(!@include_once('connect.php')) {
// include connect.php
}
Check your connection string is returning the proper linked identifier and also check the logs if there is any error or warning from mysql like Warning: mysql_query(): [2002] No such file or directory (trying to connect via unix:///var/run/mysql/mysql.sock). In that case try to set the proper socket file location.