Note that there are some explanatory texts on larger screens.

plurals
  1. PO2 Codeigniter Controller Querys on One View
    primarykey
    data
    text
    <p>How do you put two different function outputs from the same controller into the same view(page)? For example, I have a function going to the "article" div, and another function that I am trying to use within the "aside" div. (using HTML 5 nomenclature here)</p> <p>I have went as far as using the actual db query in the (view)aside div and it still only displays the 1st article function.</p> <p>I have changed the $data('result') variable to separate variables and that makes no difference.</p> <p>I am showing a todo list of jobs I have to do in the article div, then showing the titles of the completed todo's in the aside div.</p> <p>I suppose I am making a mess of this explanation. Would you use a function from a different controller?</p> <p>This is the first code in the controller</p> <pre><code>function index() { $this-&gt;load-&gt;model('work_m'); $data = array(); $config['base_url'] = base_url() . 'index.php/work/index/'; $config['total_rows'] = $this-&gt;db-&gt;count_all('work'); $config['per_page'] = '10'; $config['full_tag_open'] = '&lt;div id="pagination"&gt;'; $config['full_tag_close'] = '&lt;/div&gt;'; $this-&gt;pagination-&gt;initialize($config); $data['result'] = $this-&gt;work_m-&gt;get_records($config['per_page'], $this-&gt;uri-&gt; segment(3)); $tmpl = array('table_open' =&gt; '&lt;table border="0" cellpadding="0" cellspacing="0"&gt;', 'heading_row_start' =&gt; '&lt;tr class="heading"&gt;', 'heading_row_end' =&gt; '&lt;/tr&gt;', 'heading_cell_start' =&gt; '&lt;th&gt;', 'heading_cell_end' =&gt; '&lt;/th&gt;', 'row_start' =&gt; '&lt;tr&gt;', 'row_end' =&gt; '&lt;/tr&gt;', 'cell_start' =&gt; '&lt;td&gt;', 'cell_end' =&gt; '&lt;/td&gt;', 'row_alt_start' =&gt; '&lt;tr class="alt"&gt;', 'row_alt_end' =&gt; '&lt;/tr&gt;', 'cell_alt_start' =&gt; '&lt;td&gt;', 'cell_alt_end' =&gt; '&lt;/td&gt;', 'table_close' =&gt; '&lt;/table&gt;'); $this-&gt;table-&gt;set_template($tmpl); $this-&gt;table-&gt;set_caption("Work Items"); //-- Header Row $this-&gt;table-&gt;set_heading('ID', 'Date', 'Title', 'Done', 'Item'); //-- Content Rows $data['title'] = 'Page Display'; $this-&gt;load-&gt;view('work_links', $data); </code></pre> <p>Note it points to work_links, a view</p> <p>the next function is this</p> <pre><code>function done() { $data = array(); if ($query = $this-&gt;work_m-&gt;dead_work()) { $data['dead'] = $query; } $tmpl = array('table_open' =&gt; '&lt;table border="0" cellpadding="0" cellspacing="0"&gt;', 'heading_row_start' =&gt; '&lt;tr class="heading"&gt;', 'heading_row_end' =&gt; '&lt;/tr&gt;', 'heading_cell_start' =&gt; '&lt;th&gt;', 'heading_cell_end' =&gt; '&lt;/th&gt;', 'row_start' =&gt; '&lt;tr&gt;', 'row_end' =&gt; '&lt;/tr&gt;', 'cell_start' =&gt; '&lt;td&gt;', 'cell_end' =&gt; '&lt;/td&gt;', 'row_alt_start' =&gt; '&lt;tr class="alt"&gt;', 'row_alt_end' =&gt; '&lt;/tr&gt;', 'cell_alt_start' =&gt; '&lt;td&gt;', 'cell_alt_end' =&gt; '&lt;/td&gt;', 'table_close' =&gt; '&lt;/table&gt;'); $this-&gt;table-&gt;set_template($tmpl); $this-&gt;load-&gt;view('work_links', $data); } </code></pre> <p>The models behind them are basic calls to the database</p> <p>Now this code in the view goes with the first function above(in the article div) and works perfectly</p> <pre><code>foreach($result as $row) { $this-&gt;table-&gt;add_row( anchor("work/fill_form/$row-&gt;id", $row-&gt;id), $row-&gt;date, $row-&gt;title, $row-&gt;compl, $this-&gt;typography-&gt;auto_typography($row-&gt;item) ); } $table = $this-&gt;table-&gt;generate(); echo $table; </code></pre> <p>this is the second code to go into the aside div(and goes with the second functiin above)</p> <pre><code>if (isset($dead)){ foreach($dead as $row) { $this-&gt;table-&gt;add_row( $row-&gt;id, $row-&gt;title, $row-&gt;finish ); } } $this-&gt;table-&gt;set_heading('ID', 'Title'); $table = $this-&gt;table-&gt;generate(); echo $table; </code></pre> <p>The last code only picks up the data from the first function no matter what i do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload