Trying to figure out how to use db->where... does my code make sense? - 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: Trying to figure out how to use db->where... does my code make sense? (/showthread.php?tid=11979) |
Trying to figure out how to use db->where... does my code make sense? - El Forum - 10-01-2008 [eluser]dallen33[/eluser] Code: <? if ($ads_query->num_rows() > 0): ?> The code above works fine. I have a table called "ads" and a table called "clients". In "ads", a record can reference a client name by having the client ID. The "clients" table has the client name and ID. Simple stuff. So how do I code this wisely? I want this record's client ID to show up as the client name. Before CodeIgniter, I'd do it like this: Code: $client_rslt = $mysqli->query("SELECT * FROM clients WHERE id = '" . $ad_row->client . "'"); And then I'd show the result like this: Code: <?=$client_row->client?> What's the best way of doing this in my code now that i'm using CodeIgniter. I've tried a few things but they seem clumsy. I'm very much a newb, so any help would be great Trying to figure out how to use db->where... does my code make sense? - El Forum - 10-01-2008 [eluser]dallen33[/eluser] And this is in my controller: Code: function insertion() Trying to figure out how to use db->where... does my code make sense? - El Forum - 10-01-2008 [eluser]dallen33[/eluser] Alright, I think I figured it out, but let me know if I can do this more efficiently. Code: <? if ($ads_query->num_rows() > 0): ?> Seems to work... Trying to figure out how to use db->where... does my code make sense? - El Forum - 10-01-2008 [eluser]Jon L[/eluser] Code: $where = array('id' => $this->uri->segment(3)); EDIT: however you actually implement is up to you, my example is intended for the controller (though ideally, wouldn't it go into the model, as I believe models are meant for handling the data... bah, dang MVC...), hopefully this helps Trying to figure out how to use db->where... does my code make sense? - El Forum - 10-01-2008 [eluser]Jon L[/eluser] You can also use Code: $this->db->row_object(); I'm getting these examples from system/database/DB_result.php Trying to figure out how to use db->where... does my code make sense? - El Forum - 10-01-2008 [eluser]dallen33[/eluser] Can't believe I forgot about Models. Thanks, I really appreciate that code. I'm going to look into doing it in a Model. |