Jump to content

NEED help please


richarro1234

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.