php - How do I sort elements in a while loop? -


i'm display comments on page, works fine want display comments user first. so, how display user comments user_id first? i'm using while loop display comments.

i grateful if me. :)

                <?php                     $sql = "select * `comments` `post_id`=$pid , `active`=1 order 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                     }                 ?> 

greetings

you can prefilter data. example use

$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); 

then can display information way want to.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -