Page 1 of 1
[SOLVED] How to write this query?
Posted: Tue Apr 26, 2005 7:41 am
by paolone
hi, the problem is the following:
I have done a script, wich opens a file, i manipulate it, then i display this file with the results of the manipulation (the post titled "Loop does not work"...). now i need to send this result to the database, but i cannot figure out how to send te query to the MySql database.
first the script
Code: Select all
//get the filename and upload
$filetosql = $_REQUEST['filetosql'];
######################################
## set variable for layout ##
######################################
$font_color_head = '003066';
$alignment_head = 'center';
$bgcolor_head = '#A6ADC7';
$width_transaction_name = '320';
$width_transaction_response_time = '250';
$width_execution_time = '150';
$width_date = '150';
$total = ($width_transaction_name + $width_transaction_response_time + $width_execution_time + $width_date);
// Get the data tokenized by line (event)
$lines = file($filetosql);
$lines = str_replace('"', '', $lines);
//get the date from the file name
$filename = $filetosql;
preg_match('/_(\d{8})\.txt$/', $filename, $matches); //Extract the date
$dateRes = $matches[1]; //This is your date
//workaround the date format
$date = substr($matches[1], 4, 4) ."-". substr($matches[1], 2, 2) ."-". substr($matches[1], 0, 2);
if ($filetosql != '')
{
foreach($lines as $theLine)
{
$theLine = rtrim($theLine);
$event [] = explode("\t", $theLine);
}
print "<table width=".$total." border='0'><tr><td width=".$width_transaction_name." bgcolor=".$bgcolor_head."><div align=".$alignment_head."><font color=".$font_color_head."><strong>TRANS. NAME</strong></font></div></td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor_head."><div align=".$alignment_head."><font color=".$font_color_head."><strong>TRANS. RESPONSE TIME</strong></font></div></td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor_head."><div align=".$alignment_head."><font color=".$font_color_head."><strong>EXEC. TIME</strong></font></div></td>";
print "<td width=".$width_date." bgcolor=".$bgcolor_head."><div align=".$alignment_head."><font color=".$font_color_head."><strong>DATE</strong></font></div></td></tr>";
//set timemark
$timeMark = 0;
// Trundle through the events
foreach ($event as $theEvent)
{ //define Variable for time handling
$timeHandling = str_replace(',','',$theEvent[2]);
//define hour
$hour = (int)($timeHandling / 3600 + ;
//define minutes
$v_mins = (int)($timeHandling / 900);
$mins = (($v_mins*15) % 60);
while ($mins != $timeMark)
{
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor='red'><font color='white'>".$theEvent[0]."</font></td>";
print "<td width=".$width_transaction_response_time." bgcolor='red'><font color='white'>####</font></td>";
//print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[6]."</td>";
print "<td width=".$width_execution_time." bgcolor='red'><font color='white'>####</font></td>";
print "<td width=".$width_date." bgcolor='red'><font color='white'>".$date."</font></td>";
print "</tr>";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//alternate color on results
$bgcolor = ($bgcolor=='#E5E5E5'? '#F3F3F3' : '#E5E5E5');
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor.">".$theEvent[0]."</td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[1]."</td>";
//print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[6]."</td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor.">".$hour." : ".$mins."</td>";
print "<td width=".$width_date." bgcolor=".$bgcolor.">".$date."</td>";
print "</tr>";
if (($timeMark += 15) > 45) $timeMark = 0;
}
print "</table>";
print "<br>";
print "<input type='submit' name='submit' value='Save data'>";
}
what i need to do is insert the value in the table as:
Code: Select all
$theEventї0] in field ==> transaction_name
$theEventї1] in field ==> transaction_response_time
$hours $mins in field ==> Execution_time
$date in field ==> Date
And also the error must be inserted, it has as values
Code: Select all
$theEventї0] in field ==> transaction_name (insert the name of the transaction)
$theEventї1] in field ==> transaction_response_time (insert a '####')
$hours $mins in field ==> Execution_time (insert a '####')
$date in field ==> Date (insert the date)
thanks guys...

Posted: Wed Apr 27, 2005 4:43 am
by paolone
Sorry guys, but is this so difficult? Is there any info u need more on this?

Posted: Wed Apr 27, 2005 5:07 am
by n00b Saibot
paolone wrote:Sorry guys, but is this so difficult? Is there any info you need more on this?
~ ~ ~ keep you wording short, simple and sweet ~ ~ ~
Code: Select all
$sql = "e;INSERT INTO `table-name`
(`transaction_name`, `transaction_response_time`, `Execution_time`, `Date`)
VALUES ('{$theEventї0]}', {$theEventї1]}, {$hours}{$mins}, $date)"e;;
paolone wrote:And also the error must be inserted, it has as values
as for the error values, i don't see any. you have posted the same thing twice...
Posted: Wed Apr 27, 2005 5:15 am
by paolone
Hi.. .thanks for your reply..
For the error i mean that while the script output the value from the file, it outputs also a dummy line with only the date and the name of the script and ##### as filling for the cells... How can this be saved as well in the db?
Posted: Wed Apr 27, 2005 5:24 am
by n00b Saibot
if you put that insert in the loop it will insert everything, including your dummy/error values...
Waitaminit, does it output the values in the same vars mentioned or does it output them in some other vars... If some other vars, please mention them... else its ok.
Posted: Wed Apr 27, 2005 5:35 am
by paolone
does it output the values in the same vars mentioned
Yes..
if you put that insert in the loop it will insert everything, including your dummy/error values...
So you mean the foreach loop, where i specify $event as $theEvent... ANd i guess it should go at the end of the loop, right? I'll give it a try and start debugging it this afternoon... i'll tell u what happens...
As for this...
paolone wrote:
Sorry guys, but is this so difficult? Is there any info you need more on this?
~ ~ ~ keep you wording short, simple and sweet ~ ~ ~
I didn't mean to be rude or respectless... If this is what you understood, my apologies...
I was only asking if the problem was not clear...
sometimes ppl read a post but if is ot clear they just go futher...
thanks for now...

Posted: Thu Apr 28, 2005 10:04 am
by paolone
Code: Select all
if ($filetosql != '')
{
// Connect to DB
$db = mysql_connect("localhost", "root", "");
// Select DB
mysql_select_db("Support",$db);
foreach($lines as $theLine)
{
$theLine = rtrim($theLine);
$event [] = explode("\t", $theLine);
}
print "<table width=".$total." border='0'><tr><td width=".$width_transaction_name." bgcolor=".$bgcolor_head."><div align=".$alignment_head."><font color=".$font_color_head."><strong>TRANS. NAME</strong></font></div></td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor_head."><div align=".$alignment_head."><font color=".$font_color_head."><strong>TRANS. RESPONSE TIME</strong></font></div></td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor_head."><div align=".$alignment_head."><font color=".$font_color_head."><strong>EXEC. TIME</strong></font></div></td>";
print "<td width=".$width_date." bgcolor=".$bgcolor_head."><div align=".$alignment_head."><font color=".$font_color_head."><strong>DATE</strong></font></div></td></tr>";
//set timemark
$timeMark = 0;
// Trundle through the events
foreach ($event as $theEvent)
{
//define Variable for time handling
$timeHandling = str_replace(',','',$theEvent[2]);
//define hour
$hour = (int)($timeHandling / 3600 + ;
//define minutes
$v_mins = (int)($timeHandling / 900);
$mins = (($v_mins*15) % 60);
while ($mins != $timeMark)
{
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor='red'><font color='white'>".$theEvent[0]."</font></td>";
print "<td width=".$width_transaction_response_time." bgcolor='red'><font color='white'>####</font></td>";
//print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[6]."</td>";
print "<td width=".$width_execution_time." bgcolor='red'><font color='white'>####</font></td>";
print "<td width=".$width_date." bgcolor='red'><font color='white'>".$date."</font></td>";
print "</tr>";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//alternate color on results
$bgcolor = ($bgcolor=='#E5E5E5'? '#F3F3F3' : '#E5E5E5');
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor.">".$theEvent[0]."</td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[1]."</td>";
//print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[6]."</td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor.">".$hour." : ".$mins."</td>";
print "<td width=".$width_date." bgcolor=".$bgcolor.">".$date."</td>";
print "</tr>";
if (($timeMark += 15) > 45) $timeMark = 0;
//insert value in the database
$sql = "INSERT INTO `kpi` (`transaction_name`, `transaction_response_time`, `execution_time`, `date`) VALUES ('{$theEvent[0]}', {$theEvent[1]}, {$hour}:{$mins}, $date)";
}
print "</table>";
print "<br>";
//show the query
print_r ($sql);
}
the solution above does not insert any data in the db...
and if i dump the $sql i see only the string for the last result in the table....
Where am i wrong?

Posted: Mon May 02, 2005 1:41 am
by n00b Saibot
paolone wrote:if i dump the $sql i see only the string for the last result in the table....
You see this line...
Code: Select all
$sql = "INSERT INTO `kpi` (`transaction_name`, `transaction_response_time`, `execution_time`, `date`) VALUES ('{$theEvent[0]}', {$theEvent[1]}, {$hour}:{$mins}, $date)";
This '=' is your culprit. Instead of '.=' you used '='.
paolone wrote:the solution above does not insert any data in the db...
Now for this you have to execute the query instead of just defining it and letting it overwrited in next loop.
D
You don't have to change anything in your code. Just add following line after the above quoted line.
Code: Select all
mysql_query($sql) or die("Error: ".MySQL_Error());
Posted: Tue May 03, 2005 3:37 am
by paolone
Hi, thanks for your help... The thing is taking form now...
But is weird the behave of the script... first of all the error is displayed on the page but not inserted in the database...
Then i have the following :
this way (i publish only the loop)
Code: Select all
// Trundle through the events
foreach ($event as $theEvent)
{
//define Variable for time handling
$timeHandling = str_replace(',','',$theEvent[2]);
//define hour
$hour = (int)($timeHandling / 3600 + ;
//define minutes
$v_mins = (int)($timeHandling / 900);
$mins = (($v_mins*15) % 60);
while ($mins != $timeMark)
{
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor='red'><font color='white'>".$theEvent[0]."</font></td>";
print "<td width=".$width_transaction_response_time." bgcolor='red'><font color='white'>####</font></td>";
//print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[6]."</td>";
print "<td width=".$width_execution_time." bgcolor='red'><font color='white'>####</font></td>";
print "<td width=".$width_date." bgcolor='red'><font color='white'>".$date."</font></td>";
print "</tr>";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//alternate color on results
$bgcolor = ($bgcolor=='#E5E5E5'? '#F3F3F3' : '#E5E5E5');
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor.">".$theEvent[0]."</td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[1]."</td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor.">".$hour." : ".$mins."</td>";
print "<td width=".$width_date." bgcolor=".$bgcolor.">".$date."</td>";
print "</tr>";
if (($timeMark += 15) > 45) $timeMark = 0;
//Query to insert values in the database
$sql .= "INSERT INTO `kpi` (`transaction_name`,`transaction_response_time`,`time`,`date`) VALUES ('".$theEvent[0]."', '".$theEvent[1]."', '".$hour.":".$mins."', '".$date."')";
//Execute query
mysql_query($sql) or die("Error:".mysql_errno().": ".mysql_error()."");
}
I have the first two lines of the results printed on the page, and then the error as folowing :
Error

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO `kpi` (`transaction_name`,`transaction_response_tim
This way (i've removed the .= replaced with a simple =):
Code: Select all
foreach ($event as $theEvent)
{
//define Variable for time handling
$timeHandling = str_replace(',','',$theEvent[2]);
//define hour
$hour = (int)($timeHandling / 3600 + ;
//define minutes
$v_mins = (int)($timeHandling / 900);
$mins = (($v_mins*15) % 60);
while ($mins != $timeMark)
{
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor='red'><font color='white'>".$theEvent[0]."</font></td>";
print "<td width=".$width_transaction_response_time." bgcolor='red'><font color='white'>####</font></td>";
//print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[6]."</td>";
print "<td width=".$width_execution_time." bgcolor='red'><font color='white'>####</font></td>";
print "<td width=".$width_date." bgcolor='red'><font color='white'>".$date."</font></td>";
print "</tr>";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//alternate color on results
$bgcolor = ($bgcolor=='#E5E5E5'? '#F3F3F3' : '#E5E5E5');
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor.">".$theEvent[0]."</td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[1]."</td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor.">".$hour." : ".$mins."</td>";
print "<td width=".$width_date." bgcolor=".$bgcolor.">".$date."</td>";
print "</tr>";
if (($timeMark += 15) > 45) $timeMark = 0;
//Query to insert values in the database
$sql = "INSERT INTO `kpi` (`transaction_name`,`transaction_response_time`,`time`,`date`) VALUES ('".$theEvent[0]."', '".$theEvent[1]."', '".$hour.":".$mins."', '".$date."')";
//Execute query
mysql_query($sql) or die("Error:".mysql_errno().": ".mysql_error()."");
}
i have all the values printed (no error displayed...) on the page inserted in the database, except the errors...
Why is this happening? How can i send the errors as well?

More informations....
Posted: Tue May 03, 2005 9:33 am
by paolone
going over the script again i've noticed that the query rendered give an error in the PHP loop, but if i copy /paste the query dumped in the page, and i run it in PhpMyAdmin it works fine....
the last version of the script is the following (only the "while" loop)
Code: Select all
// Trundle through the events
foreach ($event as $theEvent)
{
//define Variable for time handling
$timeHandling = str_replace(',','',$theEvent[2]);
//define hour
$hour = (int)($timeHandling / 3600 + ;
//define minutes
$v_mins = (int)($timeHandling / 900);
$mins = (($v_mins*15) % 60);
//$sql .= "INSERT INTO `kpi` (transaction_name,transaction_response_time,theTime,theDate)";
while ($mins != $timeMark)
{
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor='red'><font color='white'>".$theEvent[0]."</font></td>";
print "<td width=".$width_transaction_response_time." bgcolor='red'><font color='white'>".$error."</font></td>";
print "<td width=".$width_execution_time." bgcolor='red'><font color='white'>".$error."</font></td>";
print "<td width=".$width_date." bgcolor='red'><font color='white'>".$date."</font></td>";
print "</tr>";
//Query to insert values in the database
$sql .= "INSERT INTO `kpi` (transaction_name,transaction_response_time,theTime,theDate) VALUES ('".$theEvent[0]."','".$error."','".$error."','".$date."'); ";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//alternate color on results
$bgcolor = ($bgcolor=='#E5E5E5'? '#F3F3F3' : '#E5E5E5');
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor.">".$theEvent[0]."</td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[1]."</td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor.">".$hour." : ".$mins."</td>";
print "<td width=".$width_date." bgcolor=".$bgcolor.">".$date."</td>";
print "</tr>";
//Query to insert values in the database
$sql .= "INSERT INTO `kpi` (transaction_name,transaction_response_time,theTime,theDate) VALUES ('".$theEvent[0]."','".$theEvent[1]."','".$hour.":".$mins."','".$date."'); ";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//Execute query
mysql_query($sql) or die(("<b>!! ERROR !!:</b> ".mysql_error())."<br><br><b>Failed query:</b> ".$sql."");
print "</table>";
print "<br>";
//print_r ($sql);
}
and the error i get is the following :
!! ERROR !!: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '; INSERT INTO `kpi` (transaction_name,transaction_response_time
What to do now?? Why the same query give an error here while it doesn't when inserted in the phpmyadmin manually?

Posted: Wed May 04, 2005 9:42 am
by paolone
Im' having a look at the concatenation operators, but cannot find an answer to this problem...
can u please help?
Posted: Tue May 17, 2005 4:03 am
by paolone
Hi again,
I'm trying to build the query but i cannot figure out how to build it with the PHP string operators...
I need to add a ";" at the end of the query, and the query is already build with the ".=" operator to add the values coming from the loop.
this is what i did:
Code: Select all
$sql = "INSERT INTO `kpi` (transaction_name,transaction_response_time,theTime,theDate) VALUES ";
//set timemark
$timeMark = 0;
// Trundle through the events
foreach ($event as $theEvent)
{
//define Variable for time handling
$timeHandling = str_replace(',','',$theEvent[2]);
//define hour
$hour = (int)($timeHandling / 3600 + ;
//define minutes
$v_mins = (int)($timeHandling / 900);
$mins = (($v_mins*15) % 60);
while ($mins != $timeMark)
{
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor='red'><font color='white'>".$theEvent[0]."</font></td>";
print "<td width=".$width_transaction_response_time." bgcolor='red'><font color='white'>".$error."</font></td>";
print "<td width=".$width_execution_time." bgcolor='red'><font color='white'>".$error."</font></td>";
print "<td width=".$width_date." bgcolor='red'><font color='white'>".$date."</font></td>";
print "</tr>";
//Query to insert values in the database
$sql .= "('".$theEvent[0]."','".$error."','".$error."','".$date."')";
$sql .= ",";
//$sql .= ",";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//alternate color on results
$bgcolor = ($bgcolor=='#E5E5E5'? '#F3F3F3' : '#E5E5E5');
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor.">".$theEvent[0]."</td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[1]."</td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor.">".$hour." : ".$mins."</td>";
print "<td width=".$width_date." bgcolor=".$bgcolor.">".$date."</td>";
print "</tr>";
//Query to insert values in the database
$sql .= "('".$theEvent[0]."','".$theEvent[1]."','".$hour.":".$mins."','".$date."')";
$sql .= ",";
if (($timeMark += 15) > 45) $timeMark = 0;
}
$sql .= ";";
//Execute query
$result = mysql_query($sql) or die(("<b>!! ERROR !!:</b> ".mysql_error())."<br><br><b>Failed query:</b> ".$sql."");
Running the above script, the query has the "," at the end, and it shouldn't be the case.
How can i avoid the comma to be added at the end of the query?
Thanks for your attention....
Posted: Tue May 17, 2005 3:12 pm
by trukfixer
paolone wrote:Hi again,
I'm trying to build the query but i cannot figure out how to build it with the PHP string operators...
I need to add a ";" at the end of the query, and the query is already build with the ".=" operator to add the values coming from the loop.
this is what i did:
Code: Select all
//set timemark
$timeMark = 0;
// Trundle through the events
foreach ($event as $theEvent)
{
//define Variable for time handling
$timeHandling = str_replace(',','',$theEvent[2]);
//define hour
$hour = (int)($timeHandling / 3600 + ;
//define minutes
$v_mins = (int)($timeHandling / 900);
$mins = (($v_mins*15) % 60);
while ($mins != $timeMark)
{
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor='red'><font color='white'>".$theEvent[0]."</font></td>";
print "<td width=".$width_transaction_response_time." bgcolor='red'><font color='white'>".$error."</font></td>";
print "<td width=".$width_execution_time." bgcolor='red'><font color='white'>".$error."</font></td>";
print "<td width=".$width_date." bgcolor='red'><font color='white'>".$date."</font></td>";
print "</tr>";
//Query to insert values in the database
$sql .= "('".$theEvent[0]."','".$error."','".$error."','".$date."')";
$sql .= ",";
//$sql .= ",";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//alternate color on results
$bgcolor = ($bgcolor=='#E5E5E5'? '#F3F3F3' : '#E5E5E5');
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor.">".$theEvent[0]."</td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[1]."</td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor.">".$hour." : ".$mins."</td>";
print "<td width=".$width_date." bgcolor=".$bgcolor.">".$date."</td>";
print "</tr>";
//Query to insert values in the database
$sql .= "('".$theEvent[0]."','".$theEvent[1]."','".$hour.":".$mins."','".$date."')";
$sql .= ",";
if (($timeMark += 15) > 45) $timeMark = 0;
}
$sql .= ";";
//Execute query
$result = mysql_query($sql) or die(("<b>!! ERROR !!:</b> ".mysql_error())."<br><br><b>Failed query:</b> ".$sql."");
Running the above script, the query has the "," at the end, and it shouldn't be the case.$sql = "INSERT INTO `kpi` (transaction_name,transaction_response_time,theTime,theDate) VALUES ";
How can i avoid the comma to be added at the end of the query?
Thanks for your attention....
do rtrim(",",$sql); before you do $sql .=";"; should clean it right up for ya
Posted: Wed May 18, 2005 2:43 am
by paolone
YES !!!!
That was it... here it is, fully working. At the end the modification of the string to delete last comma...
thanks to all of you that helped me...
Code: Select all
foreach($lines as $theLine)
{
$theLine = rtrim($theLine);
$event [] = explode("\t", $theLine);
}
print "<table width=".$total." border='0'><tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor_head."><div align=".$alignment_head.">";
print "<font color=".$font_color_head."><strong>TRANS. NAME</strong></font></div></td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor_head."><div align=".$alignment_head.">";
print "<font color=".$font_color_head."><strong>TRANS. RESPONSE TIME</strong></font></div></td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor_head."><div align=".$alignment_head.">";
print "<font color=".$font_color_head."><strong>EXEC. TIME</strong></font></div></td>";
print "<td width=".$width_date." bgcolor=".$bgcolor_head."><div align=".$alignment_head.">";
print "<font color=".$font_color_head."><strong>DATE</strong></font></div></td>";
print "</tr>";
$sql = "INSERT INTO `kpi` (transaction_name,transaction_response_time,theTime,theDate) VALUES ";
//set timemark
$timeMark = 0;
// Trundle through the events
foreach ($event as $theEvent)
{
//define Variable for time handling
$timeHandling = str_replace(',','',$theEvent[2]);
//define hour
$hour = (int)($timeHandling / 3600 + ;
//define minutes
$v_mins = (int)($timeHandling / 900);
$mins = (($v_mins*15) % 60);
while ($mins != $timeMark)
{
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor='red'><font color='white'>".$theEvent[0]."</font></td>";
print "<td width=".$width_transaction_response_time." bgcolor='red'><font color='white'>".$error."</font></td>";
print "<td width=".$width_execution_time." bgcolor='red'><font color='white'>".$error."</font></td>";
print "<td width=".$width_date." bgcolor='red'><font color='white'>".$date."</font></td>";
print "</tr>";
//Query to insert values in the database
$sql .= "('".$theEvent[0]."','".$error."','".$error."','".$date."')";
$sql .= ",";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//alternate color on results
$bgcolor = ($bgcolor=='#E5E5E5'? '#F3F3F3' : '#E5E5E5');
print "<tr>";
print "<td width=".$width_transaction_name." bgcolor=".$bgcolor.">".$theEvent[0]."</td>";
print "<td width=".$width_transaction_response_time." bgcolor=".$bgcolor.">".$theEvent[1]."</td>";
print "<td width=".$width_execution_time." bgcolor=".$bgcolor.">".$hour." : ".$mins."</td>";
print "<td width=".$width_date." bgcolor=".$bgcolor.">".$date."</td>";
print "</tr>";
//Query to insert values in the database
$sql .= "('".$theEvent[0]."', '".$theEvent[1]."', '".$hour." : ".$mins."', '".$date."')";
$sql .= ",";
if (($timeMark += 15) > 45) $timeMark = 0;
}
//strip last comma
$sql_final = rtrim($sql, ",");
//end string with ;
$sql_final .= ";";
//Execute query
$result = mysql_query($sql_final) or die(("<b>!! ERROR !!:</b> ".mysql_error())."<br><br><b>Failed query:</b> ".$sql_final."");
print "</table>";
print "<br>";