this is my code

$totalDates = "SELECT COUNT( DISTINCT date ) 
               FROM table_name";
$result = mysqli_query($connection, $totalDates);
$totalDates = mysqli_fetch_array($totalDates, MYSQLI_NUM);
echo "there are total $totalDates Distinct Rows";

i want to get the no of distinct dates from table_name but it giving me this error , what i might be doing wrong ?

Error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given

P.S : i ran the sql code in the query windows , its working fine there and gave me an integer value.

The issue isn't with the SQL which is why the query works fine. The error clearly states you are using mysql_fetch_array wrong.
You want to be passing in the result of your query, not the query string.

$totalDates = mysqli_fetch_array($result, MYSQLI_NUM);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.