ㅠㅠㅠ
{@
$oDB = &DB::getInstance();
$query5 = $oDB->_query('select count(*) as cnt from xe_comments where document_srl = '.$oDocument->document_srl.' and voted_count = 5');
$result5 = $oDB->_fetch($query5);
$query4 = $oDB->_query('select count(*) as cnt from xe_comments where document_srl = '.$oDocument->document_srl.' and voted_count = 4');
$result4 = $oDB->_fetch($query4);
$query3 = $oDB->_query('select count(*) as cnt from xe_comments where document_srl = '.$oDocument->document_srl.' and voted_count = 3');
$result3 = $oDB->_fetch($query3);
$query2 = $oDB->_query('select count(*) as cnt from xe_comments where document_srl = '.$oDocument->document_srl.' and voted_count = 2');
$result2 = $oDB->_fetch($query2);
$query1 = $oDB->_query('select count(*) as cnt from xe_comments where document_srl = '.$oDocument->document_srl.' and voted_count = 1');
$result1 = $oDB->_fetch($query1);
}
{$oDocument->document_srl} 게시물에서,
5점 등록한 사람은 {$result5->cnt} 입니다.
4점 등록한 사람은 {$result4->cnt} 입니다.
3점 등록한 사람은 {$result3->cnt} 입니다.
2점 등록한 사람은 {$result2->cnt} 입니다.
1점 등록한 사람은 {$result1->cnt} 입니다.
이온디
Lv. 13
# 라이믹스 스킨 제작은 어디? >>>> XE 레이아웃, 라이믹스 스킨제작은 이온디에서 커스터마이징해드립니다.
# 빠른 라이믹스 커뮤니티용 호스팅을 찾고 계신가요? >>>> 이온디호스팅 서비스는 PHP8 & Redis 서버 캐시를 활용하여 라이믹스에 최적화된 호스팅 서비스를 제공해드립니다. (서버세팅시 웹패널, 내도메인메일서비스도 함께 구축해드립니다.)
https://eond.com
# 빠른 라이믹스 커뮤니티용 호스팅을 찾고 계신가요? >>>> 이온디호스팅 서비스는 PHP8 & Redis 서버 캐시를 활용하여 라이믹스에 최적화된 호스팅 서비스를 제공해드립니다. (서버세팅시 웹패널, 내도메인메일서비스도 함께 구축해드립니다.)
https://eond.com
댓글 9
쿼리문은 반복문으로 안 돌아가는가 보죠?
$temp1 = "query".$i;
$temp2 = "result".$i;
$$temp1 = $oDB->_query('select count(*) as cnt from xe_comments where document_srl = '.$oDocument->document_srl.' and voted_count = '.$i.');
$$temp2 = $oDB->_fetch($$temp1);
}
이런식으로 안될려나요?
그냥 php에서는 되거든요.
아래 html부분도 for문 돌리면 되구요.
GROUP BY를 잘 사용하면 추천수별 통계를 한 번에 쫙 뽑을 수도 있습니다.
그리고 가능하면 XML 쿼리 쓰세요... 저렇게 SQL을 직접 박아넣을 버릇 하면 보안에도 안 좋고 다른 사이트에서 쓰기도 힘들어집니다. (DB 테이블 접두사를 xe_ 말고 다른 거 쓰는 사이트가 은근히 많아요.)
prefix 를 구해와서 사용하는게 좋습니다.
$db_info = Context::getDBInfo();
$prefix = $db_info->master_db['db_table_prefix'];
그리고 위에 query 문 짜실때 xe_ 부분대신에 $prefix 를 넣는거죠
점점 xe타운이 이온디님 연습장이 되시는것 같아요@.@
간단하게 쏜다면~~~
select voted_count as value, count(voted_count) as cnt
from xe_comments
where regdate between '2017-01-01' and '2017-01-31' AND
voted_count <= 5 and voted_count !=0 and document_srl= '****'
group by voted_count