Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8661793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:35:00+00:00 2026-06-12T16:35:00+00:00

Model $data = array(); $session_id = $this->session->userdata(‘id’); $q = $this->db->get_where(‘cust_orders’, array(‘cust_id’ => $id)); foreach

  • 0

Model

    $data   =   array();
    $session_id = $this->session->userdata('id'); 

    $q = $this->db->get_where('cust_orders', array('cust_id' => $id));


        foreach ($q->result() as $row)
        {
            $data['id'] = $row->cust_id; 
            $data['orders'] = $row->cart; 

        }
            return $data;

Controller

Passes the data to the view

View

<?php foreach($_orders as $key => $item) : ?>
<tr>

    <td>
    <?php 
        $price = $item['price']; #change this to order status 

        switch ($price) 
        {
        case (64); $UPSTrack = '1Z12345E1512345676'; #Shipped add tracking number
              echo 'Shipped <br> <a href="http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums='.$UPSTrack.'">Track My Order</a>'; 
              break;

        case (88);
              echo 'Shipped'; 
              break;

        default;
              echo 'Processing'; 
              break;
        }
    ?>

    </td>




    <td>
    <?php foreach ($item['options'] as $option => $value) 
            {
            echo '<span class="option">'.$option . ': </span> <span class="options">' . $value . '</span>';
            } 
    ?>
    </td>


    <td><?php echo $item['id']; ?></td>

    <td><?php echo $item['qty'];  ?></td>

    <td><?php echo number_format($item['price'],2); ?></td>

</tr>    



<?php endforeach; ?>

Options is an ARRAY

Contains a foreach which loops through the array contained in the variable $data['orders'] = $row->cart;

In the database I am looking up the cust_orders table by cust_id A customer may have more than 1 row meaning multiple orders.

The problem is that I am only looping through the last row. I need to loop through all rows where cust_id is = to $session_id.

I feel the problem is in my MODEL because if I change $data['id'] = $row->cust_id; to echo $row->cust_id;' I am able to see all of the rows which match the customers id, but it breaks myforeach` code.

How do I properly assign the values returned in the MODEL query so that all cust_orders == to $session_id are displayed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:35:02+00:00Added an answer on June 12, 2026 at 4:35 pm

    Right now, you are overwrite your array with each customer value, so you need multidimensional array.

    It should be like below

    EDIT: Change your foreach in your model as below

       foreach ($q->result() as $row)
        {
            $data['id'] = $row->cust_id; 
            $data['orders'][] = $row->cart; 
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Model $id = $this->session->userdata('id'); $q = $this->db->get_where('shipping_address', array('customer_id' => $id)); if ($q->num_rows == 0)
I'm saving my data with Array, look: Get data: $data['address'] = $this->input->post('address'); Save: $this->load->model('mymodel');
I have an array of integers in my core data model. It is set
I've got an array with data from a MySQL table in nested set model
I have a model that I'm trying to retrieve an array of data from,
my CakePHP (1.2.5.) doesn't validate my form correct. $this->UserData->save($this->data); gives me always a true
I want to return the Model (data) of a controller in different formats (JavaScript/XML/JSON/HTML)
The data model in my program has a number of discrete states, but I
In my data model I have a fairly common division between my objects/tables/data: Transactional
Is Model only Entity Data Model class of my database? Model as simple place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.