richarro1234 Posted November 20, 2010 Share Posted November 20, 2010 Hey all, im trying to make a script that will show the hours i have worked and how much i get for that day, then i need to add all the days up and output the total at the bottom of the page. So say i get £5 an hour and i do 4 hours one day 1 and 5 hours on day 2 So far the database outputs all the data like this: day1 - in 12:00, out 16:00 (hours) (£20) day2 - in 12:00 out 17:00 (5hours) (£25) now i need to add up the total for each day and output the grand total (so 20+25=£45) But i also need it to be able to add if i add a day aswell so day3 - in 12:00 out 17:00 (5hours) (£25) so now the total at the bottom of the page would be £70 Hope this makes sense to everyone, i have my code if anyone needs to see it. Thanks Rich Link to comment https://forums.phpfreaks.com/topic/219266-need-help-please/ Share on other sites More sharing options...
trq Posted November 20, 2010 Share Posted November 20, 2010 i have my code if anyone needs to see it. Impossible to help you without it. Also, you haven't actually asked any question. Do you have one? Link to comment https://forums.phpfreaks.com/topic/219266-need-help-please/#findComment-1137068 Share on other sites More sharing options...
richarro1234 Posted November 20, 2010 Author Share Posted November 20, 2010 <?php $mysql_hostname = "localhost"; $mysql_user = ""; $mysql_password = ""; $mysql_database = ""; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database"); mysql_select_db($mysql_database, $bd) or die("Could not select database"); ?> <?php $results= mysql_query("SELECT * FROM hours WHERE year = '2010'"); echo mysql_error(); if (mysql_Numrows($results)>0) //if there are records in the fields { $numrows=mysql_NumRows($results); //count them $x=0; while ($x<$numrows){ //loop through the records $thetimein=mysql_result($results,$x,"timein"); $thetimeout=mysql_result($results,$x,"timeout"); $theday=mysql_result($results,$x,"daynumber"); $themonth=mysql_result($results,$x,"month"); $theyear=mysql_result($results,$x,"year"); $worked = $thetimeout-$thetimein; $totalpay = $worked*6.40; ?> <?php echo" $theday/$themonth/$theyear: $thetimein - $thetimeout ($worked) = (£$totalpay)"; ?><br> <?php $x++; } } ?> <BR> Total pay so far is: <?php echo"$totalpay"?> Thats the code i have so far The question is: How do i do it please. Rich Link to comment https://forums.phpfreaks.com/topic/219266-need-help-please/#findComment-1137070 Share on other sites More sharing options...
DavidAM Posted November 20, 2010 Share Posted November 20, 2010 $x=0; $GrandTotal = 0; while ($x<$numrows){ //loop through the records // all your other code as is $totalpay = $worked*6.40; $GrandTotal += $totalpay; $x++; } } ?> <BR> Total pay so far is: <?php echo"$GrandTotal"?> Link to comment https://forums.phpfreaks.com/topic/219266-need-help-please/#findComment-1137077 Share on other sites More sharing options...
richarro1234 Posted November 20, 2010 Author Share Posted November 20, 2010 Awesome, Thank you very much DavidAM works a charm... Thanks so much Rich Link to comment https://forums.phpfreaks.com/topic/219266-need-help-please/#findComment-1137079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.