Problem with MySQL and CSV
Hi,
I'm having problems with my script so I need a little help...
I have two data sources, first is a MySQL DB with this colums:
HOUR DATE DATA
00:00 2012-05-07 5000
00:15 2012-05-07 6000
00:30 2012-05-07 3000
00:45 2012-05-07 7000
01:00 2012-05-07 3000
and a CSV file with this structure
HOUR MIN MAX
00:00 1000 10000
00:15 2000 7000
00:30 500 7000
00:45 100 5000
01:00 1000 4500
What is the script for?
The script gets the MySQL values for DATA and HOUR and print a line with the values for DATA, and an ABSCISA of HOUR, easy
Then, it imports a CSV file with HOUR, MIN and MAX values, like a threshold for the data each HOUR value, so this is perfectly working.
Both of MySQL and CSV data, has exactly 96 rows every day (96/4 = 24 hours a day)
I have an obiously problem, the CSV has static values that never changes, so it ALWAYS have 96 rows, but, sometimes, I cannot insert a value into MySQL so maybe that day will have 67 rows, when this happens, I have an abscisa with hours, and a line with data values for MySQL, but, a threshold line which does not correspond with the hour value, this is an example.
MYSQL
HOUR DATE DATA
00:00 2012-05-07 5000
00:15 2012-05-07 6000
01:00 2012-05-07 3000
CSV
HOUR MIN MAX
00:00 1000 10000
00:15 2000 7000
00:30 500 7000
00:45 100 5000
01:00 1000 4500
With this data, I will have a chart with messed values, because I have nothing for 00:30 and 00:45, but it will draw a threshold line with thresold values for incorrect times... I can't set VOID values to MySQL because it is an automated process...
I don't know if I explained very good, but... Basicaly what I need to do is this:
Compare both HOUR values, from MySQL and CSV, if this values are not the same, don't draw that CSV row and skip to next row. Any ideas?
This is my code
Code:
$hour=""; $date=""; $data="";
while($row = $db->fetch_array($myQuery)){
$date[] = $row["date"];
$hour[] = $row["hour"];
$data[] = $row[$_data];
}
$db->close();
$MyData = new pData();
$MyData->addPoints($data,$_data);
$MyData->setSerieDescription("TRX ".$_data,$_data);
$MyData->setSerieOnAxis($_data,0);
$MyData->setPalette($_data, array("R"=>0,"G"=>0,"B"=>0));
$MyData->setSerieWeight($_data,1);
$MyData->importFromCSV("CSV/".$day."/".$_name."/".$_second."_".$_data.".csv",array("Delimiter"=>";","GotHeader"=>TRUE));
$MyData->setPalette("MIN", array("R"=>255,"G"=>0,"B"=>0));
$MyData->setSerieOnAxis("MIN",0);
$MyData->setSerieWeight("MIN",1);
$MyData->setPalette("MAX", array("R"=>255,"G"=>255,"B"=>0));
$MyData->setSerieOnAxis("MAX",0);
$MyData->setSerieWeight("MAX",1);
//print_r($MyData->getData());
$MyData->addPoints($hour,"HOUR");
$MyData->setAbscissa("HOUR");