显示进出的询问查询

时间:2016-08-11 11:32:31

标签: php mysql

依据查询显示进出,但结束日期,然后第二天从外面开始。我的表数据是:

attendance_id student_id get_id attendance_date attendancetime create_user create_datetime     edit_user edit_datetime
            1          8      0 2016-08-02      12:10:01                 0 0000-00-00 00:00:00         0 0000-00-00 00:00:00 
            2          8      0 2016-08-02      00:00:00                 0 0000-00-00 00:00:00         0 0000-00-00 00:00:00
            3          8      0 2016-08-02      14:00 00                 0 2016-08-08 05:00:00         0 0000-00-00 00:00:00
            5          8      0 2016-08-06      06:00:00                 0 2016-08-08 05:00:00         0 0000-00-00 00:00:00
            6          8      0 2016-08-06      13:00:00                 0 2016-08-08 05:00:00         0 0000-00-00 00:00:00 
            7          8      0 2016-08-10      06:00:00                 1 2016-08-11 01:58:00         1 2016-08-11 01:58:00 
            8          8      0 2016-08-10      12:00:00                 1 2016-08-11 01:58:00         1 2016-08-11 01:58:00

我的代码是:

$dategroup_str = "SELECT  b.all_date,hostel_attendance.attendancetime,hostel_attendance.attendance_date FROM 
                            (SELECT * FROM 
                            (SELECT ADDDATE('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) all_date FROM 
                            (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t0, 
                            (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t1, 
                            (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t2, 
                            (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t3, 
                            (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t4) 
                            AS d ".$where_clause." ) AS b
                            LEFT JOIN hostel_attendance ON b.all_date = hostel_attendance.attendance_date 
                            AND  hostel_attendance.student_id='$show_student_id' order BY b.all_date";
    echo $dategroup_str;
    $dategroup_sql = $mysqli->query($dategroup_str);
    $dategroup_count = $dategroup_sql->num_rows;
    $i=1;
    $j=0;
    while($dategroup_sel = $dategroup_sql->fetch_row())
    { 
        if($i%2 != 0){?>
        <tr>
            <td class="center" style="text-transform:capitalize;"><?php echo $dategroup_sel[0];?></td>

            <td class="center" style="text-transform:capitalize;">
            <?php if($dategroup_sel[1]!=''){echo $dategroup_sel[1];}else{echo "-";}?>
            </td>
            <?php }elseif($i%2 == 0){?>
            <td class="center" style="text-transform:capitalize;">
            <?php if($dategroup_sel[1]!=''){echo $dategroup_sel[1];}else{echo "-";}?>
            </td>
         </tr>
            <?php }
        $i++; } ?>
        </tbody>
    </table>

输出是 enter image description here 我的输出显示此类型

1 个答案:

答案 0 :(得分:0)

$ datearr_str =&#34; SELECT b.all_date,hostel_attendance.attendancetime FROM                             (SELECT * FROM                             (选择添加(&#39; 1970-01-01&#39;,t4.i * 10000 + t3.i * 1000 + t2.i * 100 + t1.i * 10 + t0.i)all_date FROM                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t0,                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t1,                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t2,                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t3,                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t4)                             AS d&#34;。$ where_clause。&#34; )AS b                             LEFT JOIN hostel_attendance ON b.all_date = hostel_attendance.attendance_date                             AND hostel_attendance.student_id =&#39; $ show_student_id&#39;订单BY b.all_date,hostel_attendance.attendancetime&#34 ;;         // echo $ datearr_str;         $ datearr_sql = $ mysqli-&gt; query($ datearr_str);         $ datearr_count = $ datearr_sql-&gt; num_rows;         $ datestr =&#34;&#34 ;;         $ timestr =&#34;&#34 ;;         while($ datearr_sel = $ datearr_sql-&gt; fetch_row())         {
            if($ datestr ==&#34;&#34;){$ datestr = $ datearr_sel [0];} else {$ datestr = $ datestr。&#34;,&#34;。$ datearr_sel [0]; }             if($ timestr ==&#34;&#34;){$ timestr = $ datearr_sel [1];} else {$ timestr = $ timestr。&#34;,&#34;。$ datearr_sel [1]; }         }         $ datearr = explode(&#34;,&#34;,$ datestr);         $ timearr = explode(&#34;,&#34;,$ timestr);         //的print_r($ timearr);         $ dtgp_str =&#34; SELECT b.all_date,hostel_attendance.attendancetime,hostel_attendance.attendance_id FROM                             (SELECT * FROM                             (选择添加(&#39; 1970-01-01&#39;,t4.i * 10000 + t3.i * 1000 + t2.i * 100 + t1.i * 10 + t0.i)all_date FROM                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t0,                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t1,                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t2,                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t3,                             (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)t4)                             AS d&#34;。$ where_clause。&#34; )AS b                             LEFT JOIN hostel_attendance ON b.all_date = hostel_attendance.attendance_date                             AND hostel_attendance.student_id =&#39; $ show_student_id&#39;订单BY b.all_date,hostel_attendance.attendancetime&#34 ;;         // echo $ dtgp_str;         $ dtgp_sql = $ mysqli-&gt; query($ dtgp_str);         $ dtgp_count = $ dtgp_sql-&gt; num_rows;         $ J = 1;         $ K = 1;         $升= 1;         //的print_r($ timearr);

    while($dtgp_sel = $dtgp_sql->fetch_row())
    { 
        $all_date  = $dtgp_sel[0];
        $next_date = $datearr[$l];
        //echo $timearr[$k];
        //echo "k- ".$k;
        if($timearr[$k] !=""){$one_time_before_time = $timearr[$k];}else{$one_time_before_time = '551';}
        if($j !=$l){
            ?>          
                <tr>
                    <td class="center" style="text-transform:capitalize;"><?php echo $all_date;?></td>

                    <td class="center" style="text-transform:capitalize;">
                    <?php if($dtgp_sel[1]!=''){echo $dtgp_sel[1]; }else{echo "-";}?>
                    </td>


                    <?php //echo $all_date . "/". $next_date;
                    if(strtotime($all_date)==strtotime($next_date))
                    { ?>
                        <td class="center" style="text-transform:capitalize;"><?php  echo $one_time_before_time; ?></td> 

                    <?php $i=2; $k=$k+$i;}
                     else
                        {?>
                            <td class="center" style="text-transform:capitalize;"><?php  echo "-" ; ?></td> 
                        <?php $i=1;$k=$k+$i;  } ?>

                 </tr>
                    <?php

            //echo " j-".$j." i-".$i." l-".$l."<br>";   
         $j=$j+$i; }$l++; } ?>
        </tbody>
    </table>
                            </div>