将来自 MySQL 的多个结果与 PHP 一起添加


Adding multiple results from MySQL together with PHP

基本上我正在做一个大项目,我来到了一个空白...(作家块)。

我也在尝试添加时间表页面。我有一个包含JobID,StartTime,FinishTime的数据库。我可以得到一天的总时间很好,但我想把所有的日子加在一起?

我将数据库中的时间存储为 date('U')

打印我正在尝试执行的操作的屏幕

这是我所拥有的:

    echo "<a href=''>Arrvied on site</a><BR><a href=''>Left site</a></font>";
echo "<BR><BR><table border='0' cellpadding='0' cellspacing='0'>
    <tr>
        <td>Start</td>
        <td>Finish</td>
    </tr>";
$Total = "";    
$result3 = mysql_query("SELECT * FROM jobtime WHERE `jobid` LIKE " . $JID) or die(mysql_error());  
while($row3 = mysql_fetch_array( $result3 )) {

    echo "<tr>
        <td>" . date('H:i', $row3['start']) . "</td>
        <td>" . date('H:i', $row3['finish']) . "</td>
        <td>" . date('D d/m/Y', $row3['finish']). "</td>
        <td>" . date('H:i', $row3['finish']-$row3['start']). "</td>
    </tr>";
  $thistotal = $row3['finish']-$row3['start'];
  $Total = Total + $thistotal;
}
echo "</table><BR>Total: " . date('H:i',$Total) . " Hours<HR>";

显然,它只显示最后一个条目。

请帮忙!

好吧,你可以从中挑选骨头...

<html>
<head>
</head>
<body>
<form>
     <table id='mytable'>
      <tr>
       <td>Project</td>
       <td>Workstage</td>
       <td>Hours</td>
       <td>Description</td>
      </tr>
      <tr>
       <td></td>
       <td></td>
       <td><input size=3 id='total' disabled='disabled'/></td>
       <td></td>
      </tr>
       <tr id='row0' class="row">
       <td>
                      <select class="project" name="">
                          <option value="">Select One</option>
                        </select>
    </td><td>
                       <select class="task" name="" onchange="updateText('task')">
                           <option value="">Select One</option>
                      </select>
       </td>
       <td>
         <select name = 'hours' onmouseup="sumInputs()">
         <script language="javascript" type="text/javascript">
         for(var d=0;d<=16;d++)
         {
             document.write("<option>"+(d/2).toFixed(1)+"</option>");
         }
         </script>
         </select>
       <td><input type="text" value="" class="taskText" /></td>
      </tr>
     </table>
       <input type="button" onclick="cloneRow()" value="Add Row" />
    </form>
  </body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script>var rowNum =1;
       function cloneRow() {
          var row = document.getElementById("row0"); // find row to copy
          var table = document.getElementById("mytable"); // find table to append to
          var clone = row.cloneNode(true); // copy children too
          clone.id = "row"+rowNum; // change id or other attributes/contents
          table.appendChild(clone); // add new row to end of table
          initProject(clone.id);
          rowNum++;
        }
        function createRow() {
          var row = document.createElement('tr'); // create row node
          var col = document.createElement('td'); // create column node
          var col2 = document.createElement('td'); // create second column node
          row.appendChild(col); // append first column to row
          row.appendChild(col2); // append second column to row
          col.innerHTML = "qwe"; // put data in first column
          col2.innerHTML = "rty"; // put data in second column
          var table = document.getElementById("tableToModify"); // find table to append to
          table.appendChild(row); // append row to table
        }

    window.sumInputs = function() {
        var inputs = document.getElementsByName('hours'),
            result = document.getElementById('total'),
            sum = 0;
        for(var i=0; i<inputs.length; i++) {
            var ip = inputs[i];
            if (ip.name && ip.name.indexOf("total") < 0) {
                sum += parseFloat(ip.value) || 0;
            }
        }
        result.value = sum;
    }

    var myJson =
    {
       "listItems":[
          {
             "id":"1",
             "project_no":"1001",
             "task":[
                {
                   "task_description":"Folding stuff",
                   "id":"111",
                   "task_summary":"Folding",
                   "hours":"0.0"
                },
                {
                   "task_description":"Drawing stuff",
                   "id":"222",
                   "task_summary":"Drawing",
                   "hours":"0.0"
                }
             ]
          },
          {
             "id":"2",
             "project_no":"1002",
             "task":[
                {
                   "task_description":"Meeting description",
                   "id":"333",
                   "task_summary":"Meeting",
                   "hours":"0.0"
                },
                {
                   "task_description":"Administration",
                   "id":"444",
                   "task_summary":"Admin",
                   "hours":"0.0"
                }
             ]
          }
       ]
    }
    function initProject(rowId){
    console.log(rowId);
        if(rowId == 'row0'){
         $.each(myJson.listItems, function (index, value) {
            $("#"+rowId+" .project").append('<option value="'+value.id+'">'+value.project_no+'</option>');
          });
        }
        $('#'+rowId+' .project').on('change', function(e){
            rowElem = e.target.closest(".row");

         $('#'+rowId+' .task').html('<option value="000">Select One</option>');
          for(var i = 0; i < myJson.listItems.length; i++)
          {
            if(myJson.listItems[i].id == $(this).val())
            {
               $.each(myJson.listItems[i].task, function (index, value) {
                  $('#'+rowId+' .task').append('<option value="'+value.id+'" data-description="'+value.task_description+'">'+value.task_summary+'</option>');
              });
            }
          }
      });
      $('#'+rowId+' .task').change(function() {
      $('#'+rowId+' .taskText').val( $(this).find('option:selected').data('description') )
    })
    }
    initProject('row0');
</script>