업대이트 문 효율성 좀 질문좀 드릴께요 ? ^^ 정보
업대이트 문 효율성 좀 질문좀 드릴께요 ? ^^본문
아래와 같이 똑같은 조건으로 .
if ($member[mb_id]) {
$rate = 15; //★평가포인트 = 평가점수 * $rate
//원글 정보
$arr = sql_fetch("select mb_id from $write_table where wr_id='$wr_id'");
$source_mb_id = $arr[mb_id]; //원글 작성자의 id
//평가점수를 준 자신의 코멘트 정보들
$arr2 = mysql_fetch_array(mysql_query("select count(*) from $write_table where wr_parent = '$wr_id' and wr_is_comment ='1' and wr_11 > 0 and mb_id = '$member[mb_id]'"));
$already = $arr2[0] - 1; //원글에 평가점수를 준 자신의 코멘트 갯수 (현재꺼 제외)
//코멘트 수정시 조건을 위해 정보필요
if ($w == "cu") {
$arr3 = mysql_fetch_array(mysql_query("select wr_11 from $write_table where where wr_id='$comment_id'"));
$old_score = $arr3[0] * $rate; //수정하려는 코멘트의 평가점수
}
//동일인(원글=코멘트작성인) 또는 이미 1개이상 평가점수 준 회원인가? 또는 원글작성자가 비회원인가..
$limit = 1; //한 사람당 평가점수 줄 수 있는 갯수
if (($w == "c" && $member[mb_id] == $source_mb_id) || ($w == "c" && $already >= $limit) || !$source_mb_id) {
@mysql_query("update $write_table set wr_11='' where wr_id='$comment_id'"); //평가점수 취소
} else {
//원글에 결과 기록작업
//평가점수가 있는 코멘트 정보만 가져온다.
$result = sql_query("select wr_11 from $write_table where wr_parent = '$wr_id' and wr_is_comment ='1' and mb_id != '$source_mb_id' and wr_11 > 0 ");
$total_count = mysql_num_rows($result); //참여인원
if ($total_count) {
for ($i=0; $row=sql_fetch_array($result); $i++) {
$sum_score += $row[wr_11]; //평가점수합계
$sum_point += $row[wr_11] * $rate; //평가포인트합계
}
$average_score = $sum_score / $total_count; //평균점수
//원글의 wr_11필드에 "평균점수|참여인원|평가포인트합계|점수합계"를 구분자(|)와 함께 기록
@mysql_query("update $write_table set wr_11='$average_score|$total_count|$sum_point|$sum_score' where wr_id='$wr_id'");
}
}
}
지금아래는 wr_11만 업대이트 시키는걸 예로 되어 있는데 ..
만약 위와 같이 똑같이 내용을 wr_11 wr_12 wr_13 wr_14 wr_15 wr_16 wr_17 wr_18 wr_19
전부 업대이트 시켜 줘야 한다면 .. 어떻게 짜는게 가장 효율적인가요 ?
위와 같은 내용을 그냥 복사 해서 아래로 계속 붙여 넣기 해서 숫자만 바꾸워 줘도
업대이트가 되긴 하는데 ..
상당히 비효율적일거 같고 .. 그렇게 해도 아무 상관 없나요 ??
댓글 전체
평가가 늘 발생하지 않으니 처리하는데 채감속도는 거의 없습니다.
깔끔하지 않고 소스라인이 길어진다는 압박만....
전체만족도 ★★★★☆ 시설 ★★★★★ 친절 ★★★☆☆ 청결 ★★★★☆
좋은 방법 있으면 알려주세요. 저도 이 질문에 답을 기다립니다.
이렇게 하는 건가요? 이렇게 하면 explode 를 한번 않 쓴다는 효율성? 음...
별 차이 없는듯...
and wr_11 > 0 and mb_id = '$member[mb_id]'
=>
select sum( if( wr_11>0, 1, 0) wr_11_sum,
sum( if( wr_12>0, 1, 0) wr_12_sum,
sum( if( wr_13>0, 1, 0) wr_13_sum,
...
from $write_table where wr_parent = '$wr_id' and wr_is_comment ='1'
and mb_id = '$member[mb_id]'