0

So i have setup the code to display graph from php sql. But i cant seem to order it by todays date from a timestamp in my table. Here is my code:

<?php
include("phpgraphlib.php");
$graph=new PHPGraphLib(550,450);

$link = mysql_connect('xxx', 'xxx', 'xxx')
or die('Could not connect: ' . mysql_error());

mysql_select_db('test') or die('Could not select database');

$dataArray=array();

//get data from database
// $sql="SELECT rating, COUNT(*) AS 'datentry' FROM main_table GROUP BY rating";

$sql="SELECT rating, COUNT(*) AS 'datentry' FROM main_table GROUP BY rating";


$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
  $salesgroup=$row["rating"];
  $count=$row["datentry"];
  //add to data areray
  $dataArray[$salesgroup]=$count;
 }
}


//configure graph
$graph->addData($dataArray);
$graph->setTitle("Daily");
$graph->setGradient("lime", "green");
$graph->setBarOutlineColor("black");
$graph->createGraph();
?>

What i want to achieve is to be able to display just todays data. This specific code displays all of the data in my table.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
PICKAB00
  • 288
  • 2
  • 9
  • 23
  • I don't see an `ORDER BY timestamp` in your query. Also, `COUNT(*) AS 'datentry'` will probably cause a syntax error as it should be `COUNT(*) AS \`datentry\`` or just `COUNT(*) AS datentry` – Sean Jan 15 '17 at 05:34
  • I think I may have misunderstood the `...to order it by...`. If you just want to get today's date, you can use `...WHERE DATE(\`timestamp\`) = CURDATE()` -> http://stackoverflow.com/a/14769048/689579 – Sean Jan 15 '17 at 05:37
  • It does not give any error and works fine. though it only displays todays data. `ORDER BY timestamp` does not work either. The graph is not displayed. I am using phpgraph lib and the above php code to output that php file (myphp.php) to an image tag on html. i did try `SELECT * FROM excellent WHERE datentry >= (CURDATE() + INTERVAL 0 SECOND)` and it displays data as its supposed to. but i do not know how to apply this to the above code – PICKAB00 Jan 15 '17 at 05:39
  • You state *i want to achieve is to display just todays data. This specific code displays all of the data*, but now you say *though it only displays todays data*. I am now completely confused. – Sean Jan 15 '17 at 05:42
  • Sorry. if i run `SELECT * FROM excellent WHERE datentry >= (CURDATE() + INTERVAL 0 SECOND)` it works fine on phpmyadmin sql. And probably works for my php code. But with this code applied to my current code (current code being the code on my question which displays all data), i can not seem to get the graph working. The code on my question works fine but displays all of my records as graph. and i cant seem to get just todays values on graph – PICKAB00 Jan 15 '17 at 05:46

0 Answers0