donglang6656 2011-09-13 20:17
浏览 27

按字段分组结果

Am building a messaging system for a site, but i want it to have an instant messaging app feel. I have table with a structure like this:

<!-- language: lang-none -->
id
R_id     = Reciever's id
S_id     = Sender's Id
message
read     = 0 if unread, 1 if read
post_time
conv_id  = conversation id

I am trying to build a query that retrieves all messages pertaining to a receiving user and display it in a group format i.e all messages from a user grouped with the user's name, sort of like facebook messages.

This is the method in my model, am working with codeigniter

function get_user_conversations($user_id) {
       //Load Models
       $this->load->model('conversation_model');
       //Load helper
       $this->load->helper('date');
       //database query
       $q = $this->db->select('*')
                     ->from('conversations_inbox')
                     ->where('R_id',$user_id)
                     ->group_by('S_id')
                     ->order_by('post_time','desc')
                     ->get();
        $conversations = $q->result();
        return $conversations;
   }
  • 写回答

1条回答 默认 最新

  • dongrao9436 2011-09-13 20:45
    关注

    Maybe something like this?

    // Presuming you want the most recent ones first
    $q = mysql_query("SELECT message FROM `TABLE` WHERE `R_id`='USERNAME_HERE' ORDER BY `post_time` DESC");
    while ($row = mysql_fetch_array($q)) {
      echo "<li>Message: " . $row['message'];
    }
    

    I'm honestly not really sure what you're asking, so that's the best I can do.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?