![]() |
Create a variable in my model? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Create a variable in my model? (/showthread.php?tid=54719) |
Create a variable in my model? - El Forum - 09-21-2012 [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']); Model Code: (query here) View Code: <?php foreach ($records as $r) : ?> 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? Create a variable in my model? - El Forum - 09-21-2012 [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) { aaaand, that's it ![]() [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 ![]() [edit2] Needed to change the HTML entity to include spaces since it's otherwise just rendered as a dollar-sign ![]() Create a variable in my model? - El Forum - 09-21-2012 [eluser]ChrisF79[/eluser] Worked perfectly! Thanks |