코드를 줄일 수 있을가요?

코드를 줄일 수 있을가요?

QA

코드를 줄일 수 있을가요?

본문

/////////////// 아이디별 총 장수 자동입력(다섯명까지만 입력) //////////////////////////
// 아디디별 카운트 bo_3 아이디, bo_4 입력되는 총 장수
$bo3=explode("|",$board[bo_3]);
$bo4=explode("|",$board[bo_4]);
$rpt_1=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[0]'");
$reporter_1=$rpt_1[cnt];//아이디1
$rpt_2=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[1]'");
$reporter_2=$rpt_2[cnt];//아이디2
$rpt_3=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[2]'");
$reporter_3=$rpt_3[cnt];//아이디3
$rpt_4=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[3]'");
$reporter_4=$rpt_4[cnt];//아이디4
$rpt_5=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[4]'");
$reporter_5=$rpt_5[cnt];//아이디5
//아이디별 총 장수와 비교하여 틀릴 경우.. bo_4를 리셋
if ($bo4[0] != $reporter_1 || $bo4[1] != $reporter_2 || $bo4[2] != $reporter_3 || $bo4[3] != $reporter_4 || $bo4[4] != $reporter_5) {
 $bo4[0] = $reporter_1; $bo4[1] = $reporter_2; $bo4[2] = $reporter_3; $bo4[3] = $reporter_4; $bo4[4] = $reporter_5;
    $board[bo_4]="$bo4[0]|$bo4[1]|$bo4[2]|$bo4[3]|$bo4[4]";
    $sql = "update $g4[board_table] set bo_4 = '$board[bo_4]' where bo_table = '$bo_table'";
 sql_query($sql);
}
/////////////// 아이디별 총 장수 자동입력끝 //////////////////////////
 
사진 업로드 게시판입니다.
특정회원5명 이하를 위한 포토게시판이고요.. 이 회원들이 사진 올린 장수가 몇장인지를 각각 카운트해서 보여주고 있습니다.
 
즉 1회원이 올린장수가 00장이구, 2회원이 올린장수가 00장이구.... 이런식으로요..
중간에 더 올린사람이 잇을 것이구 삭제한 사람이 잇을 것이구 할것 같아 비교해서 총 장수와 다르면 현재 장수를 입력하는 코드입니다. 사진 1장은 1레코드 당 1장만 올릴수 있습니다.
 
wr_12에 올린사람의 아이디를 별도 저장합니다. mb_id를 사용하지 않고 wr_12를 사용합니다.
bo_table의 bo_3에 아이디와 bo_4에 장수를 쪼개서 입력합니다.
 
[질문]
카운트하는 코드가 제가 초보인지라서..ㅠㅠㅠ 넘 길고 접근할때마다 다섯번을 카운트해야하니까..ㅠㅠ
이걸 좀 한방으로 단순화시킬 수는 없을까요?

이 질문에 댓글 쓰기 :

답변 2


$rpt_1=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[0]'");
$reporter_1=$rpt_1[cnt];//아이디1
$rpt_2=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[1]'");
$reporter_2=$rpt_2[cnt];//아이디2
$rpt_3=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[2]'");
$reporter_3=$rpt_3[cnt];//아이디3
$rpt_4=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[3]'");
$reporter_4=$rpt_4[cnt];//아이디4
$rpt_5=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[4]'");
$reporter_5=$rpt_5[cnt];//아이디5
일단 이거는

for($i = 0; $i < 5; $i++){
$j=$i+1;
$rpt_$j=sql_fetch("select count(*) as cnt from $write_table where wr_is_comment = '0' and wr_12='$bo3[$i]'");
$reporter_$j=$rpt_$j[cnt];//아이디1,2,3,4,5
}
이렇게 처리하면 될거 같네요
답변을 작성하시기 전에 로그인 해주세요.
전체 234
QA 내용 검색

회원로그인

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