Begbie
10-26-2009, 11:33 PM
Hello I am new with php and I am also new with programming and basically this is a programming problem but I hope that someone could help me.
Here is the code and I'll try to explain what it is supposed to do:
<?php
$query2 ="SELECT *
FROM arbeitszeiten a, schichtumsatz s
WHERE a.schicht = s.id
";
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
$SelectedDB = mysql_select_db($dbname);
$result2 = mysql_query($query2); // query executed
echo mysql_error(); // if any error is there that will be printed to the screen
$time["field"]; //this variable is taking one row from the tabel row of time
$x = 0;
$counter = 0;
$y =0;
$check = $vonDatum; //starting date
while($row2 = mysql_fetch_array($result2)){
$x = $x + $time; // here i get sum of time from all dates that have been listed in SQL query
if ($check!=$row2["datum"]){ // check if the date is the same
$check=$row2["datum"]; //if it's not transform it
$counter ++; // count how many changes (different dates) has SQL query listed
$y = $y + $zeit; //here I get sum of time only on the day when the date is changing
}
?>
I have a database where I have on one date time of how much somebody (users) have worked (time). I want this time to calculate (for all users) => sum it. In the code above I managed to calculate for all dates but I need for each date separately so i put the counter to calculate changes of dates, and now I don't know what else to do. How to do this final step. How to calculate for each count(date) sum of time. Please help, because I am so confused now, that I don't know what to do .Thanks in advance.
Here is the code and I'll try to explain what it is supposed to do:
<?php
$query2 ="SELECT *
FROM arbeitszeiten a, schichtumsatz s
WHERE a.schicht = s.id
";
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
$SelectedDB = mysql_select_db($dbname);
$result2 = mysql_query($query2); // query executed
echo mysql_error(); // if any error is there that will be printed to the screen
$time["field"]; //this variable is taking one row from the tabel row of time
$x = 0;
$counter = 0;
$y =0;
$check = $vonDatum; //starting date
while($row2 = mysql_fetch_array($result2)){
$x = $x + $time; // here i get sum of time from all dates that have been listed in SQL query
if ($check!=$row2["datum"]){ // check if the date is the same
$check=$row2["datum"]; //if it's not transform it
$counter ++; // count how many changes (different dates) has SQL query listed
$y = $y + $zeit; //here I get sum of time only on the day when the date is changing
}
?>
I have a database where I have on one date time of how much somebody (users) have worked (time). I want this time to calculate (for all users) => sum it. In the code above I managed to calculate for all dates but I need for each date separately so i put the counter to calculate changes of dates, and now I don't know what else to do. How to do this final step. How to calculate for each count(date) sum of time. Please help, because I am so confused now, that I don't know what to do .Thanks in advance.