[eluser]Unknown[/eluser]
I have a file upload element (downloads table) to a CodeIgniter site I'm working on (my first site built using the framework) and I need to group the files by the id of a second table (developements table). So that the desired output would be:
<h3>Some Name 1</h3>
<p>Some document about something.<br />
<a href="download_1.pdf">download_1.pdf</a></p>
<p>Some document about something more.<br />
<a href="download_3.pdf">download_3.pdf</a></p>
<h3>Some Name 2</h3>
<p>Some document about something else.<br />
<a href="download_2.pdf">download_2.pdf</a></p>
This is what the tables look like:
Table 1: downloads table
Code:
id development_id summary file_name date_created
20 78 Some document about something. download_1.pdf 2008-11-27 10:35:40
21 77 Some document about something else. download_2.pdf 2008-11-27 10:36:07
22 78 Some document about something more. download_3.pdf 2008-11-28 10:33:55
Table 2: developments
Code:
id development_name project_desc investor_id file_name
78 Some Name 1 Some desc. Some desc. Some desc.... 0 image_1.jpg
77 Some Name 2 Some desc. Some desc. Some desc.... 0 image_2.jpg
And here's my current model code:
Code:
$this->db->select('downloads.id, development_id, summary, downloads.file_name, developments.id, development_name');
$this->db->join('developments', 'downloads.development_id = developments.id');
$this->db->order_by('developments.id', 'desc');
$query = $this->db->get('downloads');
return $query;
Can anyone advise on the best way to achieve this in CodeIginter?
Many thanks.