Jump to content

phpChart and mysql goes wrong


Aero77
Go to solution Solved by bsmither,

Recommended Posts

Newbie here, would love some help to find out what I'm doing wrong on this code. I'm using phpChart to make a graph. This is my code, but the graph does not appear.

<?php
require_once("phpChart_Lite/conf.php");
include 'connection.php';
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>phpChart - Basic Chart</title>
</head>
<body>
    
<?php

$query = mysqli_query($con, "SELECT krl FROM diesel WHERE sted = 'Borgeskogen' ORDER BY dato ASC");
	    
// set array
$price = array();

// look through query
while($row = mysqli_fetch_assoc($query)){

  // add each row returned into an array
  $price[] = $row['krl'];
}

//$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart');			
$pc = new C_PhpChartX(array($price),'basic_chart');			
$pc->set_animate(true);
$pc->draw();


?>

</body>
</html>
Link to comment
Share on other sites

When I add the $price array in there, this line in the "debugger" looks like this

 ___chart1= $.jqplot("__chart1", [["13.48","13.74","13.87","13.87","13.87","13.87","13.87","13.87","13.75","13.65","13.60","13.60"]], ___chart1_plot_properties);

and with the original array from the example it looks like this

 ___chart1= $.jqplot("__chart1", [[11,9,5,12,14]], ___chart1_plot_properties);

It looks like my array is getting some of these tags " added, can that be the problem ?

Link to comment
Share on other sites

Yes EG

CREATE TABLE IF NOT EXISTS testprice (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
price VARCHAR(10)
);

INSERT INTO testprice (price) VALUES
('125.99'),
('15.99'),
('12.49'),
('1.00'),
('0.50');

SELECT * FROM testprice;

+----+--------+
| id | price  |
+----+--------+
|  1 | 125.99 |
|  2 | 15.99  |
|  3 | 12.49  |
|  4 | 1.00   |
|  5 | 0.50   |
+----+--------+

Now alter the column type


ALTER TABLE `test`.`testprice`
CHANGE COLUMN `price` `price` DECIMAL(10,2) NULL DEFAULT NULL;

SELECT * FROM testprice;
+----+--------+
| id | price  |
+----+--------+
|  1 | 125.99 |
|  2 |  15.99 |
|  3 |  12.49 |
|  4 |   1.00 |
|  5 |   0.50 |
+----+--------+
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.