Welcome Guest, Not a member yet? Register   Sign In
Nested Data: Header Row with details
#1

[eluser]Tumac[/eluser]
I am having trouble visualizing how my results should be sent to a view to get the following result:

<table>
CustomerName1 -> colspan=6
Order1 Data Data Data Data Data
Order2 Data Data Data Data Data
Order3 Data Data Data Data Data
CustomerName2
Order1 Data Data Data Data Data
Order2 Data Data Data Data Data
.
.
CustomerNameX -> colspan=6
Order1 Data Data Data Data Data
Order2 Data Data Data Data Data
OrderX Data Data Data Data Data
</table>

MySQL VIEW:
Code:
SELECT
  po_header.poID,
  lu_customer_vendor.CusName,
  po_mills.millName,
  po_header.shipReqDate,
  po_destinations.destination,
  po_drying.dryDescription,
  po_length.polenDesc,
  po_origins.portofOrigin,
  lu_contacts.conName,
  po_tolerance.tolerance,
  po_header.`status`,
  po_terms.termDesc,
  lu_contacts.fax,
  po_specie.specieName
FROM
  po_header
  LEFT OUTER JOIN po_mills ON (po_mills.millID = po_header.millID)
  LEFT OUTER JOIN po_destinations ON (po_header.destID = po_destinations.destID)
  LEFT OUTER JOIN lu_customer_vendor ON (po_header.cusID = lu_customer_vendor.cusID)
  LEFT OUTER JOIN po_drying ON (po_header.dryID = po_drying.dryID)
  LEFT OUTER JOIN lu_contacts ON (po_header.contactID = lu_contacts.conID)
  LEFT OUTER JOIN po_origins ON (po_header.originID = po_origins.originID)
  LEFT OUTER JOIN po_tolerance ON (po_header.tolID = po_tolerance.tolID)
  LEFT OUTER JOIN po_length ON (po_header.polenID = po_length.polenID)
  LEFT OUTER JOIN po_terms ON (po_header.termID = po_terms.termID)
  INNER JOIN po_specie ON (po_header.specieID = po_specie.specieID)
ORDER BY
  lu_customer_vendor.CusName,
  po_header.poID


CONTROLLER:
Code:
function main() {
        $data=array();
      
        if($query=$this->po_model->getPOinfo()) {
            $data['records']=$query;
        }
         $this->load->view('po/po_main',$data);
    }

MODEL:
Code:
function getPOinfo() {
        $qry=$this->db->get('model_POHeader');
        return $qry->result();
    }

VIEW:
Code:
&lt;?php
$this->load->view('header');
?&gt;

<p><h2>Purchase Orders</h2></p>
<br />
      

<table class="tlctable">
    <tr>
        <th></th>
        <th>PO #</th>
        <th>Req Date</th>
        <th>Mill</th>
        <th>Contact</th>
        <th>Status</th>
    </tr>


&lt;?php if(isset($records)) { ?&gt;
    
    <tr>
        <td colspan="6">&lt;?php echo $records["CusName"]; ?&gt;</td>
    </tr>
    
&lt;?php
    foreach($records as $row) {
    ?&gt;

    <tr>
        <td>&lt;?php echo form_checkbox('record','selected',FALSE); ?&gt;</td>
        <td>&lt;?php echo anchor("po/viewDetail/$row->poID",$row->poID); ?&gt;</td>
        <td>&lt;?php echo $row->shipReqDate; ?&gt;</td>
        <td>&lt;?php echo $row->millName; ?&gt;</td>
        <td>&lt;?php echo $row->conName; ?&gt;</td>
         <td>&lt;?php echo $row->status; ?&gt;</td>
    </tr>
    &lt;?php }
    } else {
    ?&gt;
    No records returned
&lt;?php
}

echo '</table>';

$this->load->view('footer');
?&gt;

The CusName result currently returns "Undefined Index" error
#2

[eluser]saidai jagan[/eluser]
can u check the structure of the array ?
Code:
print_r($qry->result());
#3

[eluser]Tumac[/eluser]
I am not sure if that would give enough info as there is a lot of information returned by print_r and would require much cleanup to post.

The data is a one to many join of header and detail records. I want to summarize each customers orders (as above).

Not sure how to make it more clear than the above desired representation.

Think of it as "A Customer HAS MANY orders" When I load the model my datatable there are multiple rows duplicating customer with order number being unique.. I want to loop through the customer and group all order records for that customer. Right now if I loop through customers, it loops every row and NOT every unique customer.

i know I am missing something simple but really have brain freeze as I am new to CI.
#4

[eluser]jedd[/eluser]
Does [url="http://ellislab.com/forums/viewthread/125879/#622401"]this message[/url] address your problem?
#5

[eluser]Tumac[/eluser]
Yes I think so. So we are simply hiding the "key" output if it is repeated.
#6

[eluser]jedd[/eluser]
[quote author="Tumac" date="1260935263"]Yes I think so. So we are simply hiding the "key" output if it is repeated.[/quote]

That's the general pattern, yes.

Your original requirements showed this:
Code:
CustomerName1 -> colspan=6
   Order1 Data Data Data Data Data
   Order2 Data Data Data Data Data
   Order3 Data Data Data Data Data
CustomerName2
   Order1 Data Data Data Data Data
   Order2 Data Data Data Data Data
. . .

Obviously this implies three (Customer name, Order #, Data) layers of components. The logic should extend to that quite nicely though. You either have another dimension in your array (a nested loop) or if your data is flat, you need an additional value/flag field to identify if the inner information is repeated.

This is where seeing the actual raw view of your incoming data becomes useful.
#7

[eluser]Tumac[/eluser]
I agree and usually would post some raw data, but the data being sent back was already large.

This works now as asked in original post. THANKS!!!




Theme © iAndrew 2016 - Forum software by © MyBB