0

I'm trying to create a function that runs a query that returns all of the data located in my MySQL database.

My current code only returns the one row of data (there are 7)

function staff_get() {
    $this->load->database();
    $sql = 'SELECT * from Staff';
    $query = $this->db->query($sql);
    $data = $query->row();
    $this->response($data, 200);
}

I'd imagine it has something to do with the line "$data = $query->row();" however I've tried switching "row" with "array" but this doesn't work. The text is designed to come out as plaintext so that I can manipulate it using a jQuery template.

Thank you for your help in advance.

1
  • It's not easy to answer, since we don't know what class $this->db is. Are you using a framework or an ORM? If not, editing the database method into your question might help. Commented Mar 21, 2013 at 14:08

1 Answer 1

2

You need to encase the results in a while loop. Something along the lines of this.

function staff_get() {
    $this->load->database();
    $sql = 'SELECT * from Staff';
    $query = $this->db->query($sql);
    while($data = $query->row()) {
        $this->response($data, 200);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.