File "chart01.php"

Full Path: /home/analogde/www/download/CHESS_2022/chart01.php
File size: 1.54 KB
MIME-type: text/html
Charset: utf-8


// ne pas oublier
header('Content-type: application/json');

<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>


<script type="text/javascript">

	$(document).ready(function () {
		var source =
		{
			 datatype: "json",
			 datafields: [
				 { name: 'OrderDate', type: 'date'},
				 { name: 'Quantity'},
				 { name: 'ProductName'}
			],
			url: 'data.php'
		};

	   

	 

		
	});
</script>



<?php
	
	include('connect.php');
	# Connect to the database
	$mysqli = new mysqli($hostname, $username, $password, $database);
	/* check connection */
	if (mysqli_connect_errno())
	{
		printf("Connect failed: %s\n", mysqli_connect_error());
		exit();
	}
	
	
	// get data and store in a json array
	$from = 0;
	$to = 30;
	$query = "SELECT OrderDate, ProductName, Quantity FROM  invoices ORDER BY OrderDate LIMIT ?, ?";
	$result = $mysqli->prepare($query);
	$result->bind_param('ii', $from, $to);
	$result->execute();
	/* bind result variables */
	$result->bind_result($OrderDate, $ProductName, $Quantity);
	/* fetch values */
	while ($result->fetch())
	{
	$orders[] = array(
		'OrderDate' => $OrderDate,
		'ProductName' => $ProductName,
		'Quantity' => $Quantity
	);
	}
	echo json_encode($orders);
	/* close statement */
	$result->close();
	/* close connection */
	$mysqli->close();

	//https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxchart/jquery-chart-data-source.htm
	
?>