Copy
<?$query = "SELECT * FROM g5_board_new where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc";$sql = sql_query($query);$state_1 = sql_fetch(" select count(*) as cnt from {$g5['board_new_table']} where addarea='작업지시' ");?><style type="text/css">*{padding:0;margin:0;}table, tr, td{ border: 1px solid #ddd;}</style> <table class="table table-bordered"> <tr> <th >아이디</th> <th >작업지시</th> <th >승인대기</th> <th >승인완료</th> <th >승인거절</th> <th >작업완료</th> <th >기간만료</th> </tr> <?php while($row= sql_fetch_array($sql)) { ?> <tr> <td><?php echo $row["dateco_id"]; ?></td> <td> <?php echo $state_1['cnt']?></td> </tr> <?php } ?> </table>
질문은 이러합니다.
g5_board_new에 있는 아이디를 뿌리고, 그 아이디와 연결된 단어들의 숫자를 같이 뿌리고 싶습니다.
예)
아이디 |
작업지시 |
승인대기 |
승인완료 |
홍길동 |
10 |
0 |
5 |
장길산 |
10 |
1 |
4 |
임꺽정 |
5 |
20 |
9 |
이런식으로 해당아이디와 연결되는 단어의 숫자를 세고 싶습니다.
위 코드를 작성하면 g5_board_new에 있는 아이디는 정상적으로 뿌려집니다.
근데 그 아이디에 연결되는 단어의 숫자를 어떻게 뿌려야할지 감이 안잡혀서요,,,
혹시 도움을 구할 수 잇을까요?
아님 불가능한가요?
답변 4개 / 댓글 11개
채택된 답변
+20 포인트
2017-10-16 (월) 10:58:33
이런건 제작의뢰에 가까운 내용이지만.. 열정을 봐서
Copy
<?php$query = "SELECT x.dateco_id, (select count(*) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='작업지시') workcnt, (select count(*) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='승인대기') staycnt, (select count(*) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='승인완료') endcnt FROM (select distinct dateco_id g5_board_new where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc) x";$sql = sql_query($query);
?>
<style type="text/css">
*{
padding:0;
margin:0;
}
table, tr, td{ border: 1px solid #ddd;
}
</style>
<table class="table table-bordered">
<tr>
<th >아이디</th>
<th >작업지시</th>
<th >승인대기</th>
<th >승인완료</th><!--
<th >승인거절</th>
<th >작업완료</th>
<th >기간만료</th>-->
</tr>
<?php while($row= sql_fetch_array($sql)) { ?>
<tr>
<td><?php echo $row["dateco_id"]; ?></td>
<td> <?php echo $row['workcnt']?></td>
<td> <?php echo $row['staycnt']?></td> <td> <?php echo $row['endcnt']?></td> </tr> <?php } ?>
</table>
하시면원하는 값들을 사용하실수있습니다.답변에 대한 댓글 3개
humanb2box
2017-10-16 (월) 11:03:52
2017-10-16 (월) 11:08:49
@humanb2box
동일한 구조로
방문자의 카운트를 확인하는걸 보여드리면 무슨차이가 있는지 직접 확인가능하실겁니다.
[code]
select vi_ip,
(select count(a.vi_id) from g5_visit a where a.vi_date = curdate() and x.vi_ip = a.vi_ip) today,
(select count(a.vi_id) from g5_visit a where a.vi_date between '2017-01-01' and curdate() and x.vi_ip = a.vi_ip) toyear
from (select distinct vi_ip from g5_visit ) x
[/code]
이 코드가 보이시면 위의 내용이 정상인지 확인 가능하지 않을까요?
동일한 구조로
방문자의 카운트를 확인하는걸 보여드리면 무슨차이가 있는지 직접 확인가능하실겁니다.
[code]
select vi_ip,
(select count(a.vi_id) from g5_visit a where a.vi_date = curdate() and x.vi_ip = a.vi_ip) today,
(select count(a.vi_id) from g5_visit a where a.vi_date between '2017-01-01' and curdate() and x.vi_ip = a.vi_ip) toyear
from (select distinct vi_ip from g5_visit ) x
[/code]
이 코드가 보이시면 위의 내용이 정상인지 확인 가능하지 않을까요?
humanb2box
2017-10-16 (월) 11:53:33
[code]
"select dateco_id,
(select count(a.dateco_id) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='작업지시') cnt_1,
(select count(a.dateco_id) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='승인대기') cnt_2
from (select distinct dateco_id from g5_board_new where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc) x ";
[/code]
이렇게 하니까 되네요!
조언 감사합니다.
"select dateco_id,
(select count(a.dateco_id) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='작업지시') cnt_1,
(select count(a.dateco_id) from g5_board_new a where a.dateco_id = x.dateco_id and addarea='승인대기') cnt_2
from (select distinct dateco_id from g5_board_new where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc) x ";
[/code]
이렇게 하니까 되네요!
조언 감사합니다.
그누보드5배우자
2017-10-20 (금) 03:53:20
고수시네염 ㄷㄷ
2017-10-16 (월) 10:38:01
이렇게 쿼리 하시면 되는거 아닌가요?
select dateco_id
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업지시') as count_1
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인대기') as count_2, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인완료') as count_3
from g5_board_new out
답변에 대한 댓글 8개
2017-10-16 (월) 10:48:55
[code]
$query = "위에 쓴 쿼리
where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc";
$sql = sql_query($query);
...
<td><?php echo $row["dateco_id"]; ?></td>
<td><?php echo $row['count_1']?></td>
<td><?php echo $row['count_2']?></td>
<td><?php echo $row['count_3']?></td>
[/code]
$query = "위에 쓴 쿼리
where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc";
$sql = sql_query($query);
...
<td><?php echo $row["dateco_id"]; ?></td>
<td><?php echo $row['count_1']?></td>
<td><?php echo $row['count_2']?></td>
<td><?php echo $row['count_3']?></td>
[/code]
humanb2box
2017-10-16 (월) 10:55:51
[code]
$query = "select dateco_id
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업지시') as count_1
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인대기') as count_2
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인완료') as count_3
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인거절') as count_4
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업완료') as count_5
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='기간만료') as count_6
from g5_board_new out where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc";
$sql = sql_query($query);
<?php
$cnt=0;
while($row= sql_fetch_array($sql)) {
?>
<tr>
<td><?php echo $row['dateco_id']; ?></td>
<td><?php echo $row['count_1']?></td>
<td><?php echo $row['count_2']?></td>
<td><?php echo $row['count_3']?></td>
<td><?php echo $row['count_4']?></td>
<td><?php echo $row['count_5']?></td>
<td><?php echo $row['count_6']?></td>
</tr>
<?php $cnt++; } ?>
[/code]
아무것도 안나오네요...
$query = "select dateco_id
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업지시') as count_1
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인대기') as count_2
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인완료') as count_3
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='승인거절') as count_4
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='작업완료') as count_5
, (select count(*) from g5_board_new in where in.dateco_id = out.date_co_id and in.addarea='기간만료') as count_6
from g5_board_new out where dateco_id != '' and dateco_id != 'epro' and dateco_id != 'admin' ORDER BY wr_id desc";
$sql = sql_query($query);
<?php
$cnt=0;
while($row= sql_fetch_array($sql)) {
?>
<tr>
<td><?php echo $row['dateco_id']; ?></td>
<td><?php echo $row['count_1']?></td>
<td><?php echo $row['count_2']?></td>
<td><?php echo $row['count_3']?></td>
<td><?php echo $row['count_4']?></td>
<td><?php echo $row['count_5']?></td>
<td><?php echo $row['count_6']?></td>
</tr>
<?php $cnt++; } ?>
[/code]
아무것도 안나오네요...
2017-10-16 (월) 11:00:54
혹시 {$g5['board_new_table']} 랑 g5_board_new 랑 다른 테이블인가요?
2017-10-16 (월) 11:07:54
아마도 방식은 맞는거 같은데 쿼리를 수정해볼수 있으면 좋겠지만 해볼수 없으니 답답하네요 ^^
2017-10-16 (월) 13:15:24
그냥 서브쿼리를 이용한 방법만 알려드린거데...
@플래토 님 말씀처럼 오류는 좀 있네요 ^^
@플래토 님 말씀처럼 오류는 좀 있네요 ^^
2017-10-16 (월) 10:26:32
그 부분을 별도 카운팅의 쿼리를 해서 처리해 주셔야 할듯 보여 집니다. 한번에 카운팅을 해서 처리할수 있는 부분이 아닌부분 입니다.
답변을 작성하려면 로그인이 필요합니다.
근데 ㅠㅠ 아무것도 나오지 않네요..