-1

The below query works fine whenever I try it in phpmyadmin:

SELECT CAST(DATETIME AS DATE), Provider, COUNT(Provider) 
FROM purchases 
GROUP BY CAST(DATETIME AS DATE), Provider 
ORDER BY CAST(DATETIME AS DATE) DESC

Nevertheless I always received a boolean when I placed it inside my PHP script:

$sql="SELECT CAST(DATETIME AS DATE), Provider, COUNT(Provider) 
FROM purchases 
GROUP BY CAST(DATETIME AS DATE), Provider 
ORDER BY CAST(DATETIME AS DATE) DESC";


if (mysqli_query($con,$sql))
  {

    $result = mysql_query($sql);
    while($row = mysql_fetch_assoc($result)) {
    echo $row['CAST(DATETIME AS DATE)'];
    echo $row['Provider'];
    echo $row['COUNT(Provider)'];

}

}
else
  {
  echo "Error creating table: " . mysqli_error($con);
  }

mysqli_close($con)

;

I really would appreciate some advice about how to tackle this issue.

Marc Delisle
  • 8,879
  • 3
  • 29
  • 29
Khodor
  • 1
  • Your code is really a big mess, first of all I recommend you to re-write the code. You begin with mysqli , after that you use MySQL_* - it's deprecated... and else - error creating table? What table are you creating? – AnTrakS Sep 04 '18 at 13:37
  • Add `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` to the top of your script. This will force any mysqli_ errors to generate an Exception that you can see on the browser as well as normal PHP errors. – RiggsFolly Sep 04 '18 at 13:40

1 Answers1

0

this code write like below so its work fine

you use mysqli in all query and check if $result has value than print record otherwise error message was print

$result = mysqli_query($con,$sql);
if($result)
{
    while($row = mysqli_fetch_assoc($result)){
        echo $row['CAST(DATETIME AS DATE)'];
        echo $row['Provider'];
        echo $row['COUNT(Provider)'];

    }
}
else
{
    echo "Error creating table: " . mysqli_error($con);
}

mysqli_close($con)
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
  • 1
    And an explanation of what you chaaged and why you changed it would also make this question worth an upvote, and be useful to other that may see it in the future – RiggsFolly Sep 04 '18 at 13:42