while 로 일주일 조회시 공백있으면

while 로 일주일 조회시 공백있으면

QA

while 로 일주일 조회시 공백있으면

본문

고수님들 안녕하세요.

 


    <?
    $sql_search = " where (1) ";
    $sql_order = " order by mb_name";
    $sql = " select mb_name from {$g5['member_table']} {$sql_search} {$sql_order}";
    $result = sql_query($sql);    for ($i=0; $rows=sql_fetch_array($result); $i++) {
        $y++;
        $mb_name = $rows['mb_name'];
        ?>
        <tr >
            <td align=center><strong><?php echo $y ?></strong></td>
            <td align=center><strong ><?php echo $mb_name?></strong></td>
            <td align=center><strong >
            <div class="office_time_go">출근시간: </div>
            <div class="office_time_end">퇴근시간: </div>
            <div class="office_time_alltime">근무시간: </div>
            <div class="office_time_overtime">오버타임: </div>
            </strong></td>
        <?php
            $beforeDay = date("Y-m-d", strtotime($n_dahg." +$a day"));
            $sql_office_time = "SELECT wr_name,wr_2, wr_7,wr_15,wr_16,wr_3,wr_4 FROM $write_table WHERE wr_is_comment = 0 and wr_3 between '$n_dahg' and '$e_dahg' and wr_name ='$mb_name'";
            $result_office_time = sql_query($sql_office_time);
            while($row=sql_fetch_array($result_office_time)){
 
            $yoil = calculate_yoil($beforeDay);
        if($row['wr_3'] && (!$row['wr_2'] || strpos($row['wr_2'], "오전") || strpos($row['wr_2'], "오후")) ){
            ?>
            <td align=center> 
                    <div class="office_time_go"><?php echo substr($row['wr_3'], 11, 5); ?></div>
                    <div class="office_time_end"><?php if($row['wr_3'] != $row['wr_4']) echo substr($row['wr_4'], 11, 5); ?></div>
                
                <?php if(!$row['wr_7']){ ?> 
                    <div class="office_time_alltime" style="background-color:yellow;">
                <?php }else { ?> 
                    <div class="office_time_alltime" >
                <?php } ?> 
                    <font style="padding-top:3px"> <?php echo $row['wr_7'] ?></font>
                    </div>
                <?php if($row['wr_2']){ ?> 
                    <div class="office_time_overtime" style="background-color:#92d050;">
                <?php }else { ?> 
                    <div class="office_time_overtime" >
                <?php } ?> <div><?php if($row['wr_2']){ echo $row['wr_2']; }else{ echo $row['wr_15']; } ?></div>
                    </div>
            </td>
            <?php
        }else if($row['wr_2']) {
            ?>
            <td >
            <div class="office_time_go"></div>
            <div class="office_time_end"></div>
            <div class="office_time_alltime"></div>
            <div class="office_time_overtime" style="background-color:#92d050;"><?php echo $row['wr_2'] ?></div></td>
            <?php
        }else{
            ?>
            <td>
            <div class="office_time_go"></div>
            <div class="office_time_end"></div>
            <div class="office_time_alltime"></div>
            <div class="office_time_overtime"></div>
            </td>
            <?php
        }
            ?>
        <?php 
        }
            $sql_office_overtime = "SELECT wr_name,sum(wr_8),sum(wr_16) FROM $write_table WHERE wr_is_comment = 0 and wr_3 between '$n_dahg' and '$e_dahg'  and wr_name ='$mb_name'";
            $result_office_overtime = sql_query($sql_office_overtime);
            $row_office_overtime=sql_fetch_array($result_office_overtime);
            $office_time_color='';
            if($row_office_overtime['sum(wr_8)'] > 187200){
                $office_time_color = 1;
            }
        ?>
            <td align=center> 
            <div class="office_time_go"> </div>
            <div class="office_time_end"> </div>
            <div class="office_time_alltime" <?php if($office_time_color == 1){ ?> style="background:red;" <?php } ?> > <?php if($row_office_overtime['sum(wr_8)']) echo office_time($row_office_overtime['sum(wr_8)']); ?></div>
            <div class="office_time_overtime"> </div>
            </td>
            <td align=center> 
            <div class="office_time_go"></div>
            <div class="office_time_end"></div>
            <div class="office_time_alltime"></div>
            <div class="office_time_overtime"><?php if($row_office_overtime['sum(wr_8)'] > 187200) echo office_time($row_office_overtime['sum(wr_16)']); ?></div>
            </td>
        </tr>
    <?php
    } 
    ?>

 

으로 일주일 기록 조회하고, 근무총 시간수와 오버타임은 따로 조회하는데,  

금,토 요일에 근무시간이 없거나 휴가면, 근무총 시간수와 오버타임이 앞으로 땡겨져 노출됩니다.

 

어떤방법으로 근무시간이 없거나 근무총시간과 오버타임이 제일뒤에 노출되게 할까요?

 

 

순서 이름 내용 23

24

25

26

27

28

29

근무 총 시간수 오버타임
1 관리자

출근:

퇴근:

근무:

오버타임:

08:30

20:00

9시간 30분

1시간 30분

08:30

20:00

9시간 30분

1시간 30분

08:30

20:00

9시간 30분

1시간 30분

08:30

17:30

8시간 0분

08:30

20:00

9시간 30분

1시간 30분

58시간 25분

9시간 55

 

 

이 질문에 댓글 쓰기 :

답변 3

타이틀의 일자/요일 출력하는 코드가 없고 변수에 대한 설명도 없으니 이해가 어려우나
해당 일자가 없으면 빈 td를 출력해주어야 테이블 셀의 열이 맞게 생성이 됩니다
wr_3에 들어가는 값도 보아야 정확한 코드를 만들 수가 있겠네요
하여튼 시작일(월욜)이 $beforeDay인거죠?
 wr_3에 들어가는 날짜가 년-월-일 형식이라면 아래처럼 하면 되겠습니다


    while($row=sql_fetch_array($result_office_time))  $list[$row['wr_3']] = $row;
    $startDay = $beforeDay;
    for($n =0; $n < 7; $n++){
      $currD= date("Y-m-d", strtotime("$startDay +$n day");
      if( !isset($list[$currD]) ){ echo '<td></td>'; continue; }
      else $row= $list[$currD];
 
 

제가 쓰는 방법은

날짜 테이블을 십년 이상 저장하고

이 테이블과 위에서 사용하신 select하고 left 조인하는 것입니다.

이렇게 하면 내역이 없다 하더라도 빈칸?을 차지하는 row가 생기기 때문이죠.

답변을 작성하시기 전에 로그인 해주세요.
전체 38
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT