Welcome Guest, Not a member yet? Register   Sign In
foreach in mail
#11

[eluser]E303[/eluser]
Thanks for that tonanbarbarian, I seem to be getting closer but now the return is:

<p>D D<br />3 3<br /> </p>

It should have printed out <p> Demo 2 32.50<br /></p> instead it seems to grab the $item_row['title'] & $item_row['price'] twice but only use the first charaters.
#12

[eluser]TDSPower[/eluser]
Have you tried to echo $item_row[’title’] & $item_row[’price’].

Maybe the error come from your DB, not from the foreach.
#13

[eluser]E303[/eluser]
Yes,

Code:
$items = '';
foreach($row1 as $item_row)
                    {
                         $items .= $item_row['title'].' '.$item_row['price'].'<br />';
                                        
                     }

The error seems to be when I run the above code.

Is there any other way of reading a foreach loop into the mail function?
#14

[eluser]Seppo[/eluser]
The solution is

Code:
//Replace this
$row1 = $product_data->row();
// with this
$row1 = $product_data->result_array();
#15

[eluser]E303[/eluser]
already done that. I am starting to think that maybe there is an error in the row_array(); code?

*Update

I tried result_array(); which through back errors so that doesn't work.
#16

[eluser]E303[/eluser]
I have update the code from what I originally posted. What I have found out is that when there is only 1 item the entire name gets email (which is the idea). When there is two items or more that is when I get this first charater business.

Code:
function mailOrder()
    {
        /* GRABS INFO FROM ORDERED ITEMS */
        $sessionid = $this->session->userdata['session_id'];
        
        $query = array('session_id' => $sessionid);
        
        $this->db->select('id, title, price, session_id');
        $this->db->from('ordered_items');
        $this->db->where($query);
        $item_data = $this->db->get();
                
        if ($item_data->num_rows() > 0)
        {
                $row = $item_data->row_array();
                /* USERS ORDERED ITEMS PRODUCT_ID's TO GET PRODUCT DATA */
            
                $items = '';
                foreach($row as $item_row)
                    {
                         $items .= $item_row['title']."<br />";
                                        
                     }
                
                /*USE ORDERED ITEMS SESSION_ID's TO GET USER DATA */
                
                
                $query2 = array('id' => $Osessionid);
                
                $this->db->select('username');
                $this->db->from('orders');
                $this->db->where($query2);
                $user_data = $this->db->get();
                
                $row2 = $user_data->row();
                
                $uname = $row2->username;
                $query3 = array('username' => $uname);
                $this->db->select('fname, lname, phone, email, address, address2, postcode, state');
                $this->db->from('users');
                $this->db->where($query3);
                $postal_data = $this->db->get();
                
                $row3 = $postal_data->row();
                                    
                $emailMessage = "<h1>Order</h1>
                                        <h3>Postal Address</h3>
                                        <p>To:". $row3->fname ." ". $row3->lname ."<br />
                                        Address:". $row3->address ."<br />
                                        Address 2:". $row3->address2 ."<br />
                                        Postcode:". $row3->postcode ."<br />
                                        State:". $row3->state ."<br />
                                        Phone:". $row3->phone ."<br />
                                        Email:". $row3->email ."
                                        
                                        
                                        </p>    
                                        <h3>Ordered Items</h3>                
                                        <p>" . $items . " </p>";
        
                $this->email->from('[email protected]', 'Online Ordering');
                $this->email->to('[email protected]');
                $this->email->subject('An online order');
                $this->email->message($emailMessage);    
        
                $this->email->send();

            
        }
                
    }




Theme © iAndrew 2016 - Forum software by © MyBB