2014-12-06 5 views
0

페이지에 댓글을 표시하려고하는데 모든 것이 잘 작동하지만 사용자의 댓글을 먼저 표시하고 싶습니다. 그렇다면 먼저 user_id의 사용자 주석을 어떻게 표시합니까? 나는 while 루프를 사용하여 주석을 표시합니다.while 루프에서 요소를 어떻게 정렬합니까?

누구든지 나를 도울 수 있다면 매우 감사 할 것입니다. :)

   <?php 
        $sql = "SELECT * FROM `comments` WHERE `post_id`=$pid AND `active`=1 ORDER BY ups-downs DESC"; 
        $result = $mysqli->query($sql); 
        $count = $result->num_rows; 

        if($count == 1){ 
         $counttext = "1 Comment"; 
        }else{ 
         $counttext = $count ." Comments"; 
        } 
       ?> 
       <div class="media-area media-area-small"> 
        <h3 class="text-center"><?php echo $counttext; ?></h3> 
       <?php 
        while($row = $result->fetch_assoc()){ 
         $uid = (int)$row["user_id"]; 
         $user = get_user_info($mysqli,$uid); 
       ?> 
        <div class="media"> 
         <a class="pull-left" href="#"> 
          <div class="avatar"> 
           <img class="media-object" src="<?php echo $user["picture"]; ?>" alt="..."> 
          </div> 
         </a> 
         <div class="media-body"> 
          <table width="100%"> 
           <tr valign="middle"> 
            <td align="left"><h4 class="media-heading text-left"><?php echo fb_clear_name($mysqli, $user["id"]); ?></h4></td> 
            <td align="right"><h6 class="pull-right text-muted"><?php echo $row["ups"] - $row["downs"]; ?> bits</h6></td> 
           </tr> 
          </table> 
          <p><?php echo htmlentities($row["content"]); ?></p> 
          <div class="media-footer"> 
           <a href="#" class="btn btn-info btn-simple "> <i class="fa fa-reply"></i> Reply</a> 
           <a href="#" class="pull-right text-muted"> 
            <?php echo $row["timestamp"]; ?> 
           </a> 
          </div>  
         </div> 
        </div> 
       <?php 
        } 
       ?> 

인사말

+0

도움이 될 수 있도록 예제 코드를 제공하십시오. – melanholly

+0

아, 죄송합니다. 코드가 추가되었습니다. – user3434770

+0

데이터를 특정 방식으로 정렬하려면 응용 프로그램 코드가 아닌 DB에서이 작업을 수행해야합니다. 이 일을 방해하는 것이 있습니까? –

답변

0

당신은 데이터를 프리 필터 할 수 있습니다. 예를 들면 다음과 같습니다.

$user_comments=array(); 
$other_comments=array(); 

while($row = mysql_fetch_assoc($result)) 
{ 
    if($row['user']==$current_user) 
    { 
     $user_comments[]=$row; 
    } 
    else 
    { 
     $other_comments[]=$row; 
    } 
} 
$comments=array_merge($user_comments,$other_comments); 

그런 다음 원하는 방식으로 정보를 표시 할 수 있습니다.

+0

대단히 감사합니다! 나는 그것을 나중에 시험 할 것이다 :) – user3434770