I have a PHP loop generating a dataset for a chart. It queries two fields I have in a database table.
<?php
$server = "myserver:1234";
$user="dbuser";
$password="userpass";
$database = "dbname";
$connection = mysql_connect($server,$user,$password);
$db = mysql_select_db($database,$connection);
$query = "SELECT X, Y FROM dbtable";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
$dataset1[] = array($row['X'],$row['Y']);
}
$final = json_encode($dataset1,JSON_NUMERIC_CHECK);
?>
Currently data in X
is meaningless (it's actually an ID
column), and a number increment of 1 starting at 1 will be more useful. This is because I only want to plot a line chart, where X values are fixed. ID
would be fine but the values put distracting axis labels on my chart.
How can I use PHP to generate this instead of the database select that I currently have?
Many thanks:)