查询无效

时间:2017-06-15 06:39:11

标签: php mysql

HTML代码:

      <table width="409" border="1">
        <tr>
            <td><strong>Employee Name:</strong></td>  
             <th scope="col" align="left">             
            <select name="empid" id="empid">

          <option></option>
            <?php
          while($row = @mysql_fetch_array($result)) 
            {
       echo " <option value='$row[employeeid]'> $row[employeename] </option>";
            }
             ?>
           </select>
          </td>
          </tr>
        <!-- <tr>
            <td><strong>Employee Name:</strong></td>
            <th scope="col" align="left">
            <select name="employeename" id="employeename">
            <option></option>
          <?php
          while($row = @mysql_fetch_array($queryb)) 
            {
               echo "<option value='". $row['employeeid'] . "'>" . $row['fullname']."</option>"; 
            }
            ?>
         </select>
         </td></th>
         </tr>-->
           <!--   <tr>
            <td><strong>Date:</strong></td>
            <th scope="col" align="left">
             <input type="date" name="date" id="date" />
          </tr>-->
          <tr>
            <th scope="row">&nbsp;</th>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <th scope="row">&nbsp;</th>
            <td><input type="submit" name="submitsearch" id="submitsearch" value="Search" /></td>
          </tr>
        </table>

如果我想点击搜索按钮并以这种方式生成结果。

EnNo TotalHours  12 HH:MM  28 HH:MM

数据库表视图: 没有EnNo INOUT DateTime 1 12 S 2017-06-02 08:35 2 28 S 2017-06-02 10:10 3 28 E 2017-06-02 13:00 4 12 E 2017-06-02 14:02 5 12 S 2017-06-02 15:03 6 12 E 2017-06-02 19:04

我的查询是:

$ resultatt =&#34; SELECT EnNo,SEC_TO_TIME(SUM(TIME_TO_SEC(DateTime)))AS Totalhours FROM dataimport其中EnNo =&#39; $ _ POST [empid]&#39; GROUP BY EnNo&#34 ;;

但结果不是产生的?????????????????????

3 个答案:

答案 0 :(得分:0)

您需要更改查询,如下所示:

$resultatt = "SELECT EnNo,SEC_TO_TIME(SUM(TIME_TO_SEC(`DateTime`))) AS  
Totalhours FROM dataimport where EnNo = '$_POST[empid]' GROUP BY EnNo"; //IF you need single record only

$resultatt = "SELECT EnNo,SEC_TO_TIME(SUM(TIME_TO_SEC(`DateTime`))) AS  
Totalhours FROM dataimport GROUP BY EnNo"; //IF you need all records group by employee

答案 1 :(得分:0)

try the below query

$resultatt = "SELECT EnNo,SEC_TO_TIME(SUM(TIME_TO_SEC(`DateTime`))) AS  
Totalhours FROM dataimport where EnNo = '".$_POST[empid]."' GROUP BY EnNo";

答案 2 :(得分:0)

我刚刚创建了一个名为dataimport

的临时表

Table Format

并写了一个查询,

SELECT EnNo,work_dt,         SEC_TO_TIME(sum(TIMESTAMPDIFF(SECOND,登录,注销)))作为time_worked 来自(     选择EnNo,日期(DateTime)作为work_dt,DateTime作为登录         ,合并(               (选择MIN(DateTime)                从dataimport起b                在哪里a.EnNo = b.EnNo                  和日期(a。DateTime)=日期(b。DateTime)                  和b。DateTime&gt; = a。DateTime                  和b。INOUT =&#39; E&#39;               ),now())AS注销     来自dataimport AS     在哪里。INOUT =&#39; S&#39; )作为t GROUP BY EnNo,work_dt

最后输出为

Output

希望这就是你所看到的。