How to populate values ​​in a table that are retrieved from mysql database using PHP?

Problem: Fill the time values ​​in the table by date using PHP, MySQL and HTML.

Review: Developing a Web Application for Managing an Employee List,

  • The user selects a Monday date and all other week dates are automatically filled in.
  • The user fills in his / her time spent on a specific task and submits (every end of the day he / she does)
  • Let's say the user fills in and submits the summary sheet on Monday and on Tuesday logged into the web application, when the user selects a date and clicks the "SubmitDate" button, all previous date values ​​(Monday) must be filled in and must be up (not editable). time-sheet
    Code (for tabular logic)

                        Assignments 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('Y-n-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('Y-n-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 (for entering values ​​into 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 to get data and fill it in one table according to the date?

I am glad of any missing detail, if any. Help would be appreciated.

+3


source to share


1 answer


After using 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 to make selections that you can get in the fields. For example, 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 echoes of different days.

0


source







All Articles