Welcome Guest, Not a member yet? Register   Sign In
Generate Table from DB Query - Newbie question

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.

class Rentals extends Controller {

    function Rentals()

    function index()
        $this->load->view('summary', $data);

    function pending( $order=0 )
        // get the requested pending rental order (gets a single record)
        $data['pending']=$this->db->get_where('rental_orders', array('order_id =' => $order));
        // get all the records from 'rental_orms' that have order_id=$order.  
        // this builds the list of item_id records to fetch from the 'rental_items' table
        $data['orms']=$this->db->get_where('rental_orms', array('order_id =' => $order));
        // calculate the list of rental items to display on the pending rental order page
        foreach( $data['orms']->result_array() as $itemq )
            $data['items']=$this->db->get_where('rental_items', array('item_id =' => $itemq['item_id']));
        $this->load->view('pending', $data);

When the requested url is
the value 2 is passed to the method called pending() in the rentals.php controller. The method pending() queries 'rental_orms' to retrieve all records having the user-selected order_id. The resulting records are stored in data['orms'].

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

Messages In This Thread
Generate Table from DB Query - Newbie question - by El Forum - 04-27-2009, 12:16 PM
Generate Table from DB Query - Newbie question - by El Forum - 04-28-2009, 05:57 AM
Generate Table from DB Query - Newbie question - by El Forum - 04-29-2009, 06:16 PM

Theme © iAndrew 2016 - Forum software by © MyBB