Jump to content

Recommended Posts

Hi,

 

Apologies if this is extremely trivial, I'm new to PHP.

 

I'm trying to convert a timesheet application which I've had as an Access database into a Mysql/php driven website to get it out of the constraints of a VPN and in to the open where it will be much easier to work with.

 

I've got the data entry working fine but have run into problems trying to get the SQL right to add up the hours each person spend actually working. Each user logs in and sets a week number to record their work - these are both stored as session variables and appear on the forms automatically. My problem starts on the summary page. Each user needs to be able to see an overview of the work they done and how many hours they spent working / travelling. I've managed to get the page to calculate and display the time spend but I can't get it to display the data just for the logged in user and week number they are reviewing.

 

My code is as follows:

 

  <?php $sql = "SELECT HoursSpentLas, TravelTimeLas FROM tblProjects WHERE AdviserName = $MM_Username AND WeekNumber = $MM_Weeknumber";

$query = mysql_query($sql);

while($row = mysql_fetch_assoc($query)){ echo $query['HoursSpentLas'];

}

 

 

$TimeWorkedLAs = "SELECT HoursSpentLas, SUM(HoursSpentLas) FROM tblProjects GROUP BY WeekNumber";

 

$result = mysql_query($TimeWorkedLAs) or die(mysql_error());

 

// Print out result

while($row = mysql_fetch_array($result)){

echo "Total = ". $row['SUM(HoursSpentLas)'];

 

}

?>

 

 

Currently, its adding up fine but displaying the results for everyone. Any suggestions gratefully received!

 

Many thanks

Dave

 

change

$sql = "SELECT HoursSpentLas, TravelTimeLas FROM tblProjects WHERE AdviserName = $MM_Username AND WeekNumber = $MM_Weeknumber";

to

$sql = "SELECT HoursSpentLas, TravelTimeLas FROM tblProjects WHERE AdviserName = '$MM_Username' AND WeekNumber = $MM_Weeknumber";

add qoutes around string data

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.