Welcome Guest, Not a member yet? Register   Sign In
Create a variable in my model?
#1

[eluser]ChrisF79[/eluser]
This is a very remedial question I'm sure but I have the following:

Controller
Code:
$data['records'] = $this->property_model->getOneProperty($data['mls_listing_id']);
$this->load->view('property', $data);

Model
Code:
(query here)

if($q->num_rows() > 0) {
    foreach ($q->result() as $row) {
    $data[] = $row;
    }
return $data;

View
Code:
<?php foreach ($records as $r) : ?>
<th>Asking Price:</th>
<td>$&lt;?php echo number_format($r->SALE_PRICE); ?&gt;</td>

I've trimmed most of the detail away for a simple example.

My question is, the query pulls things like the street number, street name, city, state, zip, etc. I want to combine all of that into a "address" variable. How do I do it in my model so that I can use it as $r->address; in my view?
#2

[eluser]PhilTem[/eluser]
In your model, when looping over the database/query results, you would just create a new object attribute and store your info in it like e.g.

Code:
if($q->num_rows() > 0) {
  foreach ($q->result() as $row) {
    $row->address = "prepare your address here";
    $data[] = $row;
  }
return $data;

aaaand, that's it Wink


[edit]
BTW, you might want to use & # 3 6 ; (without the spaces) instead of $ to make it the correct HTML entity and display correctly on all clients' encodings Wink

[edit2]
Needed to change the HTML entity to include spaces since it's otherwise just rendered as a dollar-sign Tongue
#3

[eluser]ChrisF79[/eluser]
Worked perfectly! Thanks




Theme © iAndrew 2016 - Forum software by © MyBB