테스트 사이트 - 개발 중인 베타 버전입니다

함수 이렇게 만들면 되는지요? 채택완료

히어1 10년 전 조회 3,742

댓글중 내 댓글이 잇는경우 색상을 변경하는 함수를 만들엇는데 제대로 만든건지 모르겟네요..

마스터분들 보시기에는 한심할지모르지만 가르침좀 부탁합니다.

좀더 간편하게 만들방법이나 문제 지적요.

 

get_mydet($list[$i][wr_comment], $bo_table, $list[$i][wr_id]);

 

// 내댓글이 잇는지 function get_mydet($comment, $bo_table, $wr_id) {  global $g5, $member;       $mydet= '';  if ($comment) { //////////////////////////본인코멘트가 잇는경우    $sql = "select count(wr_id) cnt from $g5[write_prefix]$bo_table where wr_parent='$wr_id' and wr_is_comment=1 and mb_id='{$member[mb_id]}' "; $cnt = sql_fetch($sql);

if ($cnt['cnt']>0) {     $mydet= "".$comment.""; }else{  $mydet= "".$comment.""; }

 } //////////////////////////본인코멘트가 잇는경우

    return $mydet; }​

 

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
10년 전

list.skin.php 상단에 위에 작성한 함수를 넣고,

 

</p><p><code class="spaces"></code><code class="variable">$list</code> <code class="plain">= set_has_my_comment(</code><code class="variable">$list</code><code class="plain">, </code><code class="variable">$bo_table</code><code class="plain">, </code><code class="variable">$member</code><code class="plain">[</code><code class="string">'mb_id'</code><code class="plain">]); </code></p><p>

 

이렇게 하면 $list[$i]['has_my_comment'] 가 설정됩니다. 즉, 내 댓글이 있는 글의 경우에는 'has_my_comment' 가 true 로 설정이 되죠. for 문 안에서 각 항목을 출력할 때, 사용하시면 됩니다.

 

히어1님 코드처럼 표현하자면..  

 

</p><p>// list.skin.php 의 목록 출력 루틴 </p><p>for($i=0; $i<count($list); $i++) {</p><p>... </p><p>      if($list[$i]['has_my_comment']) {  </p><p>          $mydet= "<span class=\"det_my\" title=\"내가 작성한 댓글이 있음.\">".​$list[$i]['comment_cnt']."</span>";
     } else {
          $mydet= "<span class=\"det\">".$list[$i]['comment_cnt']."</span>";
     }  </p><p>...</p><p>} // for </p><p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

10년 전

devdev 님 댓글처럼.. 리스트 항목 개수만큼 쿼리를 실행하게 해야 하는데 그것보다는 한번에 처리하는게 어떨까요..

 

</p><p>function set_has_my_comment($list, $bo_table, $mb_id)
 {
   $write_table = $GLOBALS['g5']['write_prefix'].$bo_table;
   $wr_ids = array();
   foreach($list as $row) {
     array_push($wr_ids, $row['wr_id']);
   }</p><p>   // 게시판 목록의 wr_id 들을 콤마로 연결한 문자열로 만듬 </p><p>   $wr_ids_list = implode($wr_ids, ',');
   $sql = "SELECT wr_id, wr_parent FROM $write_table WHERE wr_parent IN ($wr_ids_list) AND wr_is_comment=1 and mb_id='$mb_id' GROUP BY wr_parent";
   $res = sql_query($sql);
   $has_my_comment = array();
   while($row = sql_fetch_array($res))
   {
     array_push($has_my_comment, $row['wr_parent']);
   }
 for($i=0; $i<count($list); $i++)
   {
     if(in_array($list[$i]['wr_id'], $has_my_comment)) {
       $list[$i]['has_my_comment'] = true;
     } else {
       $list[$i]['has_my_comment'] = false;
     }
   }
   return $list;
 } </p><p> </p><p>  // 목록 항목마다 'has_my_comment' 설정  </p><p> $list = set_has_my_comment($list, $bo_table, $member['mb_id']); </p><p> </p><p> // 내 댓글이 있는 경우, 없는 경우.. 출력해봄 </p><p> foreach($list as $row) {
   if($row['has_my_comment']) echo $row['wr_subject'] . ' : has my comment 
';
   else echo $row['wr_subject'] . ' : does not have my comment 
';
 } </p><p>
 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

히어1
10년 전
소스까지 직접 만들어주시고 정말 감사합니다.
제가 만든게 게시판 리스트,최신글등등에 써먹을거라 부하를 감안하더라도 사용이 불가피한데
만들어주신 소스는 제 수준으로는 활용을 어덯게 해야하는지 모르겟네요 ;;;

댓글을 작성하려면 로그인이 필요합니다.

d
10년 전

별 문제는 없어 보입니다.

다만.. 리스트에서 실행하면 목록마다 sql을 실행시키게 되니..

DB에 부하는 가겟죠. 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

히어1
10년 전
어차피 자신의 댓글이 잇는지 한번은 찾아야하기에 어쩔수 없어 보입니다 ㅡㅜ 답 감사합니다.

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인