Welcome Guest, Not a member yet? Register   Sign In
Need some DB help
#4

[eluser]Firestorm ZERO[/eluser]
Right now I got it working like this...

Code:
$this->db->select(*);
$this->db->from('books');

$query = $this->db->get(); // Get all the books in the book table

if ($query->num_rows() >= 1) // I got books!
{
    $result = $query->result_array(); // Change it to an array

    foreach ($result as &$row) // Go through each row in the array
    {
        // Get the author(s) of each row(book) from the bridge table
        $this->db->select('author.name');
        $this->db->from('book_author');
        $this->db->join('author', 'book_author_id = author.author_id', 'left');
        $this->db->where('book_id', $row['book_id']);

        $query = $this->db->get();

        $row['author'] = $query->result_array();
    }

    return $result;
}
else
{
    // No books!
    return FALSE;
}

Looks pretty big :/ So I don't know if it is the best way.


Messages In This Thread
Need some DB help - by El Forum - 03-12-2008, 04:07 PM
Need some DB help - by El Forum - 03-12-2008, 06:30 PM
Need some DB help - by El Forum - 03-12-2008, 06:45 PM
Need some DB help - by El Forum - 03-12-2008, 07:04 PM
Need some DB help - by El Forum - 03-13-2008, 03:17 AM
Need some DB help - by El Forum - 03-13-2008, 07:29 AM
Need some DB help - by El Forum - 03-13-2008, 07:50 AM
Need some DB help - by El Forum - 03-13-2008, 08:49 AM
Need some DB help - by El Forum - 03-13-2008, 01:50 PM
Need some DB help - by El Forum - 03-13-2008, 02:37 PM
Need some DB help - by El Forum - 03-13-2008, 03:08 PM
Need some DB help - by El Forum - 03-13-2008, 07:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB