Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The MODEL</p> <pre><code>function addressForMap($id) { $this-&gt;db-&gt;select('b.id, b.busaddress, b.buscity, b.buszip'); $this-&gt;db-&gt;from('business as b'); $this-&gt;db-&gt;where('b.id', $id); // add a limit $this-&gt;db-&gt;limit(1); // get the results.. cha-ching $q = $this-&gt;db-&gt;get(); // any results? if($q-&gt;num_rows() !== 1) { return FALSE; } return $q-&gt;row(); } </code></pre> <p>The CONTROLLER</p> <pre><code>function your_controller_method($id) { $data = $this-&gt;Business_model-&gt;addressForMap($id); // did we get any results? if($data === FALSE) { show_error(); return; } $marker['address'] = $data-&gt;busaddress.' '.$data-&gt;buscity.', '.$data-&gt;buszip; } </code></pre> <p>Make sure you validate that <code>$id</code> is an actual numerical id. It's a good thing to do before actually performing the query.. IMO.</p> <p><strong>EDIT #2: See changed code above</strong></p> <hr> <p><strong>EDIT #1: From your comment and changes</strong></p> <p>You've got this: </p> <pre><code>return $this-&gt;db-&gt;get(); </code></pre> <p>when, based on the rest of your code, it should be this:</p> <pre><code>$query = $this-&gt;db-&gt;get(); </code></pre> <p>When you return the query object, the variable <code>$address</code> gets assigned the CI result object. so, in your controller, you would actually have to do something like this:</p> <pre><code>$address = $this-&gt;Business_model-&gt;addressForMap($id); $row = $address-&gt;row(); $marker['address'] = $row-&gt;busaddress .' '.$row-&gt;buscity .', '. $row-&gt;buszip; </code></pre> <p>Still... I would suggest changing <code>return</code> to <code>$query =</code> and you could keep your controller as it is.</p>
 

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