简体   繁体   中英

How do i fill values into table, which are got from mysql database using PHP?

Problem Statement: Fill the time values into table with respect to dates using PHP, MySQL and HTML.

Overview: Developing a web application to manage time-sheet of employees,

  1. User selects Monday date and all the other week dates gets filled automatically.
  2. User fills his/her time taken for the particular task and submit ( each end of the day s/he does that)
  3. Lets say user fills and submits the time-sheet on Monday, and logs in on Tuesday to web app, when user selects the date and click on 'SubmitDate' button all the previous date values ( Monday's) should get filled and should get freezes ( non-editable). 时间表
    Code(for table logic)

    Tasks Monday Tuesday Wednesday Thursday Friday Saturday Sunday

      <tr> <th>DATES</th> <?php //while ($a <7):?> <th> <?php //$output = getStartAndEndDate(2, 2015); echo $output?> </th> <?php //$a++; ?> <?php //endwhile ?> </tr> <?php $sdate = $_SESSION['start_date1'];?> <?php $parts = explode('-', $sdate);?> <tr> <th>DATES</th> <?php $year=$parts[0]?> <?php $time = strtotime("$parts[2].$parts[1].$year", time());?> <?php $day = date('w', $time); ?> <?php $time += ((7*$week)+1-$day)*24*3600;?> <?php $return[0] = date('Yn-j', $time);?> <th> <?php echo "$return[0] <br>"; ?> </th> <?php $m = 0;?> <?php while ($m<6):?> <?php $i=1; ?> <!-- <?php $time// += ((7*$week)+1-$day)*24*3600;?> --> <?php $time += $i*24*3600; ?> <?php $return[1] = date('Yn-j', $time); ?> <!-- <?php //echo "$return[1] <br>"; ?> --> <th> <?php echo "$return[1] <br>"; ?> </th> <?php $m++; ?> <?php endwhile ?> </thead> <?php foreach ($separateTaskList as $val1):?> <tr> <th> <?php echo $val1?></th> <td contenteditable="true"> 0</td> <td contenteditable="true"> 0</td> <td contenteditable="true"> 0</td> <td contenteditable="true"> 0</td> <td contenteditable="true"> 0</td> <td contenteditable="true"> 0</td> <td contenteditable="true"> 0</td> </tr> <?php endforeach; ?> </tbody> </table> <div class="container" style="text-align:center"> <button style="" onclick="actionSend()" class="btn-default-submit submitbtn" align="center">SUBMIT</button></div> 

Code( to push values to db):

$stmt = $dbh->prepare("INSERT INTO timesheet_details 
(emp_id, tmsheet_week_start_dt, tmsheet_activity_dt, project_id, task_id, 
activity_tm_spent_min, tmsheet_status, tmsheet_submit_dt, tmsheet_approve_dt, tmsheet_approver_id ) 
 VALUES 
($emp_id, '$tmsheet_week_start_dt', '$tmsheet_week_start_dt', '$project_id', '$task_id' , $_totalMinutes, 'Notapproved', '$tmsheet_week_start_dt', '$tmsheet_week_start_dt', 1000 );");

$stmt->execute();

Question: How do i retrieve the data and fill on the same table according to date?

I am happy to any missing detail if any. Help would be appreciated.

After you use the following code

$stmt = $dbh->prepare("INSERT INTO timesheet_details 
(emp_id, tmsheet_week_start_dt, tmsheet_activity_dt, project_id, task_id, 
activity_tm_spent_min, tmsheet_status, tmsheet_submit_dt, tmsheet_approve_dt, tmsheet_approver_id ) 
 VALUES 
($emp_id, '$tmsheet_week_start_dt', '$tmsheet_week_start_dt', '$project_id', '$task_id' , $_totalMinutes, 'Notapproved', '$tmsheet_week_start_dt', '$tmsheet_week_start_dt', 1000 );");

$stmt->execute();

Try and do a fetch all which you can retrieve into the fields. For example do a fetch all and grab the values from the database .

Example:

$stmt = $dbh->prepare("Select * FROM timesheet_details WHERE emp_id = $emp_id");
$stmt->execute 

Then in HTML just get the echo the different days.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM