0
        $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

2

4 Answers 4

1
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;
Sign up to request clarification or add additional context in comments.

Comments

0
$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?

Comments

0

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.

Comments

0

you are missing ) at max(convert(custom_var_v1,unsigned)

mysql_* functions are dprecated, use mysqli_ or PDO

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.