Problems with displaying tmesheet info in one row

Hi There

I need help wrt to my sql query that I am using to display employees timesheet information, as I would like the info to display in one row per employee. At the moment it displays numerous rows for a employee with the different time in and time out times from Sunday to saturday in different rows.

This is the sql:

$ts_timesheet = $wpdb->get_results(“SELECT wp_wpts.ID, wp_wpts.ts_author, date_format(wp_wpts.ts_time_in,’%M %e, %Y’), wp_wpts.ts_job_name, wp_wpts.ts_description, date_format(wp_wpts.ts_time_in, ‘%h:%i %p’), date_format(wp_wpts.ts_time_out, ‘%h:%i %p’), SEC_TO_TIME(TIMESTAMPDIFF(SECOND,wp_wpts.ts_time_in,ts_time_out)),wp_usermeta.meta_value, TIMESTAMPDIFF(SECOND,wp_wpts.ts_time_in,ts_time_out)/3600*wp_usermeta.meta_value FROM wp_wpts, wp_usermeta, wp_users WHERE wp_wpts.ts_time_in >= '”.$ts_d1."’ AND wp_wpts.ts_time_out <= ‘".$ts_d2."’ AND wp_usermeta.user_id = wp_wpts.ts_author AND wp_usermeta.meta_key =‘Bill_Rates’ AND wp_users.ID=wp_wpts.ts_author ORDER BY wp_users.user_login ASC,wp_wpts.ts_time_in", ARRAY_N);

And display in html is:

<?php for ($i = 0; $i < sizeof($ts_timesheet); $i++) { if ($i&1) {$alternate = 'alternate';} else {$alternate = '';} $curauth = get_userdata($ts_timesheet[$i][1]); ?> <?php //display Employee Name echo $curauth->user_login?> <?php //display Job Name echo $ts_timesheet[$i][3]?> <?php //display Job Description echo $ts_timesheet[$i][4]?>
Add <?php if (current_user_can('manage_options')) { ?> | Edit<?php } ?>
<?php //display Time in for Saturday $Day = date('l', strtotime( $ts_timesheet[$i][2])); if ($Day =="Saturday"){ echo $ts_timesheet[$i][5]; }//end if ?> <?php //display Time out for Saturday if ($Day =="Saturday"){ echo $ts_timesheet[$i][6]; }//end if ?> <?php if ($Day =="Sunday"){ echo $ts_timesheet[$i][5]; }//end if ?> <?php if ($Day =="Sunday"){ echo $ts_timesheet[$i][6]; }//end if ?> <?php if ($Day =="Monday"){ echo $ts_timesheet[$i][5]; }//end if ?> <?php if ($Day =="Monday"){ echo $ts_timesheet[$i][6]; }//end if ?> <?php if ($Day =="Tuesday"){ echo $ts_timesheet[$i][5]; }//end if ?> <?php if ($Day =="Tuesday"){ echo $ts_timesheet[$i][6]; }//end if ?> <?php if ($Day =="Wednesday"){ echo $ts_timesheet[$i][5]; }//end if ?> <?php if ($Day =="Wednesday"){ echo $ts_timesheet[$i][6]; }//end if ?> <?php if ($Day =="Thursday"){ echo $ts_timesheet[$i][5]; }//end if ?> <?php if ($Day =="Thursday"){ echo $ts_timesheet[$i][6]; }//end if ?> <?php if ($Day =="Friday"){ echo $ts_timesheet[$i][5]; }//end if ?> <?php if ($Day =="Friday"){ echo $ts_timesheet[$i][6]; }//end if ?> <?php //display Total Hours for employee echo substr($ts_timesheet[$i][7], 0, -3)?> <?php //display Charge rate of employee echo $ts_timesheet[$i][8]?> R <?php //display Total amount paid echo $ts_timesheet[$i][9]?> <?php }//end for loop ?>

to do what you want you would need to edit the css script not this one.

With that being said, why?
So much information will probably involve side scrolling,
why would you want to inflict that on your users when it’s not necessary?

Red :wink:

Hi Red

Yes, it will involve scrolling but the client wants to be able to see the timesheet info on the screen and then download it in csv format.
Would you be able to advise how the css should look like please to make the info in own row per employee?

The two bits of text i have bolded, let me explain…
Leave the display as is - i haven’t seen it because i don’t have all the details but i’m assuming it’s been styled to fit on screen and look a bit clean and tidy.

Next, to download it as csv, you do not need to alter the layout on screen!
check here at the php manual about csv files

If, after all that you still want to change it, then post up the css file and i’ll take a look - I still think it’s a bad idea though :o

Red. :wink:

Ps: I’m off out now will be back in a couple of hours. :wink:

Hi There

Thanks for your reply, I have the spreadsheet creating the csv to some degree but the main issue is really the display on the screen of the records in more than one row for the same contractor.

Here are temp login details to see what I mean:
http://capecore.co.za/timesheet/wp-admin/admin.php?page=wpts-reports.php
Username: admin
Password: mohegan

U can see the two rows for the default report when using the url above displays two rows for Smokey with the same job name and time in and time out data for Thursday and Friday.

I just want to combine the two rows please so that the time in and time out for the second row for Friday is in the row as Thursday.

I think the sql needs to be changed to Group the records?

PS: U need to scroll the browser to the right quite a bit to see the info for Friday and Sat.

Sponsor our Newsletter | Privacy Policy | Terms of Service