douran9707 2018-06-21 04:04
浏览 42

按字母顺序重新排列Mysql数据

i have a marks table with studentid, marks, class_id, exam_id. i got marks and student_id from

$mark_query = $this->db->get_where('mark' , 
                                    array('class_id' => $class_id, 
                                           'exam_id' => $exam_id)
                );

After getting the marks and student_id i am displaying the marks with the student Name which i got it from another table with the student_id from the above query. I have a another table which have the student_id and their name.

The output is like this

Sajiv 25
Arun 35
Sonu 32
Binu 45

But i want to display the names in Ascending order.

Any ideas? I am using codeigniter.

  • 写回答

2条回答 默认 最新

  • dtx6087 2018-06-21 06:02
    关注

    Join the student table with mark table and order by student name in ascending order

        $this->db->select('students_table.name, mark.marks')
        ->from('mark')
        ->join('students_table', 'mark.student_id = students_table.id')
        ->where(['class_id' => $class_id, 'exam_id' => $exam_id])
        ->order_by('students_table.name', 'ASC')
        ->get();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测