Home forums Using CanvasJS MySQL – (Displaying Date-Time values on a Chart Axis) Reply To: MySQL – (Displaying Date-Time values on a Chart Axis)

#22017

JohnSnowGum
Member

I’m not sure what I’m doing wrong, but I have a feeling it’s my JSON code… Here is a jsfiddle using my JSON and here is the code behind my JSON

<?php

$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli('localhost',$username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT date FROM db";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
	$obj = array();
    while($row = $result->fetch_assoc()) {
		$element = array($row["ban_date"]);
       	array_push($obj,$element);
	}
	echo json_encode($obj);
} else {
    echo "0 results";
}
$conn->close();
?>