Reputation: 58
$avg_pgt = mysql_query("SELECT avg(convert(custom_var_v1,unsigned)),min(convert(custom_var_v1,unsigned)), max(convert(custom_var_v1,unsigned) FROM `table_name` WHERE server_time BETWEEN '$date 00:00:00' AND '$date 23:59:59'");
$row_all = mysql_fetch_array($avg_pgt);
$string_avg = (string)$row_all[0];
echo $string_avg;
It gives an error mysql_fetch_array() expects parameter 1 to be a resource boolean given in the code
Upvotes: 0
Views: 70
Reputation: 32740
you are missing )
at max(convert(custom_var_v1,unsigned)
mysql_* functions are dprecated, use mysqli_ or PDO
Upvotes: 0
Reputation: 1149
max(convert(custom_var_v1,unsigned)
Is missing a ) at the end, This would work:
$avg_pgt = mysql_query("SELECT avg(convert(custom_var_v1,unsigned)),min(convert(custom_var_v1,unsigned)), max(convert(custom_var_v1,unsigned)) FROM `table_name` WHERE server_time BETWEEN '$date 00:00:00' AND '$date 23:59:59'");
$row_all = mysql_fetch_array($avg_pgt);
$string_avg = (string)$row_all[0];
echo $string_avg;
Upvotes: 1
Reputation: 13558
You shouldn't be using the mysql_* functions since they are being deprecated since php5.
Use PDO or mysqli!
From the mysql_query() documentation page:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
Call mysql_error() to find out what is going wrong.
Upvotes: 0
Reputation: 46900
$avg_pgt = mysql_query("SELECT avg(convert(custom_var_v1,unsigned)),min(convert(custom_var_v1,unsigned)), max(convert(custom_var_v1,unsigned) FROM `table_name` WHERE server_time BETWEEN '$date 00:00:00' AND '$date 23:59:59'");
This query is failing and mysql_query
is returning false
. Check if your query is fine and returns results elsewhere. Is table_name
really the name of your table?
Upvotes: 0