This query fetches all the student name and there ids on basis of topics but i want to get these result on basis of ascending marks ... i.e select student_name and ids where student_topic = topic but fetch them in the ascending order of there topic_marks
how and where should i add ->orderby() or ->order()

  $myTable = $this->_connection->getTableName('Students');
        $sql = $this->_connection->select()->from(
            ["tn" => $myTable], array('student_name', 'student_id')
        )->where('student_topic = ?', $topic);
        $result = $this->_connection->fetchAll($sql);
        return $result;
  • 2
    ->order('topic_marks ASC') try it or ->order('topic_marks', 'asc');
    – Aman Alam
    Commented Jan 15, 2019 at 20:40

1 Answer 1


try this one

$myTable = $this->_connection->getTableName('Students');
    $sql = $this->_connection->select()
        ["tn" => $myTable], array('student_name', 'student_id'))
        ->where('student_topic = ?', $topic)
        ->order ('topic_marks','asc');
    $result = $this->_connection->fetchAll($sql);
    return $result;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.