Generate Table from DB Query - Newbie question - 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: Generate Table from DB Query - Newbie question (/showthread.php?tid=18160) |
Generate Table from DB Query - Newbie question - El Forum - 04-27-2009 [eluser]seanloving[/eluser] Hi. Newbie here (let me know if I'm doing things right or wrong on this forum). For a given rental order I need to display a list of associated rental items. Three classes (tables) are modeled as follows: rental_items(item_id, item_desc, mfr_pn, mfr_sn) rental_orders(order_id, customer, salesman) rental_orms(orm_id, order_id, item_id) The index() of the default rentals.php controller puts all the records from 'rental_orders' in data['pending'] and sends it to the summary.php view for use as $pending. Code: class Rentals extends Controller { When the requested url is Code: example.com/index.php/rentals/pending/2 Now my problem is here. Instead of generating the table of records from 'rental_orms', I want to generate a table of records from 'rental_items', based on the same list of returned item_id values from the previous query of 'rental_orms'. In my pending.php view (not shown) $items only contains the last expected record. In my controller code above, how do I make data['items'] include all the records before my call to the pending.php view?? Thanks for any advice. Sean Loving Generate Table from DB Query - Newbie question - El Forum - 04-28-2009 [eluser]TheFuzzy0ne[/eluser] Welcome to the CodeIgniter forums. If I understand you correctly, this is what you need: Code: $data['items'][]=$this->db->get_where('rental_items', array('item_id =' => $itemq['item_id'])); The way it's done currently, it overwrites the $data['items'] variable. By appending a set of empty square brackets, $data['items'] is treated as an array, and the new database result is pushed onto the end of that array. Hope this helps. Generate Table from DB Query - Newbie question - El Forum - 04-29-2009 [eluser]seanloving[/eluser] Yes that helps, thanks. Seems like I'm still learning the difference between objects and arrays, and in CI I'm trying to understand when to use result() and result_array(). I saw the post on "num_rows() always showing 0", but I think OO might be my problem. I will explore in another post... |