?
Solved

Functions and variables

Posted on 2015-02-20
2
Medium Priority
?
103 Views
Last Modified: 2015-02-21
I have a function:

<?php
public function policy_display($keep_extra = FALSE)	{
	ini_set('display_errors',1);
	ini_set('display_startup_errors',1);
	error_reporting(-1);
	
	
	$order_ids = $this->EE->TMPL->fetch_param('order_id');

	
	if (empty($order_ids)) {
		$this->EE->TMPL->log_item('You must be logged a customer and logged in for Policy data to be available');
		return $tagdata;
	} 
	
			
		$this->load->helper('data_formatting');
		
		if ($order_ids)
		{
			if ( ! is_array($order_ids))
			{
				$this->db->where('order_id', $order_ids);
			}
			else
			{
				$this->db->where_in('order_id', $order_ids);
			}
		}
		
		$query = $this->db->order_by('order_id, row_order', 'asc')
				  ->get('cartthrob_order_items');
		
		$order_items = $query->result_array();
		
		$query->free_result();
		
		foreach ($order_items as &$row)
		{
			$extra = _unserialize($row['extra'], TRUE);
			
			if ($keep_extra)
			{
				$row['extra'] = $extra;
			}
			else
			{
				foreach ($extra as $key => $value)
				{
					if ( ! isset($row[$key]))
					{
						$row[$key] = $value;
					}
				}
				
				unset($row['extra']);
			}
		}

		echo '<pre>';
		var_dump($order_items);
		echo '</pre>';	
	 return $order_items;
	} 
?>

Open in new window


On the page I have included it on, I get the proper Var_Dump
array(1) {
  [0]=>
  &array(41) {
    ["row_id"]=>
    string(2) "21"
    ["row_order"]=>
    string(1) "0"
    ["order_id"]=>
    string(2) "62"
    ["entry_id"]=>
    string(2) "29"
    ["title"]=>
    string(24) "Bicycle Insurance Policy"
    ["site_id"]=>
    string(1) "1"
    ["quantity"]=>
    string(1) "1"
    ["price"]=>
    string(3) "779"
    ["price_plus_tax"]=>
    string(3) "779"
    ["weight"]=>
    string(1) "0"
    ["shipping"]=>
    string(1) "0"
    ["no_tax"]=>
    string(1) "1"
    ["no_shipping"]=>
    string(1) "1"
    ["entry_date"]=>
    string(10) "1424383348"
    ["discount"]=>
    int(0)
    ["product_deductible"]=>
    string(5) "0.800"
    ["product_liability"]=>
    string(3) "135"
    ["product_medical"]=>
    string(3) "264"
    ["product_contact"]=>
    string(2) "54"
    ["type_bicycle"]=>
    string(23) "Electric / Pedal Assist"
    ["manufacturer"]=>
    string(12) "Manufacturer"
    ["year_built"]=>
    string(4) "2015"
    ["model"]=>
    string(5) "Model"
    ["bicycle_material"]=>
    string(8) "Aluminum"
    ["usage"]=>
    string(0) ""
    ["purchase_price"]=>
    string(14) "Purchase Price"
    ["purchase_date"]=>
    string(4) "2015"
    ["accessories_value"]=>
    string(4) "1000"
    ["attached_accessories"]=>
    string(26) " Attached Accessories List"
    ["first_name"]=>
    string(19) "Operator First Name"
    ["last_name"]=>
    string(18) "Operator Last Name"
    ["bicycle_location"]=>
    string(11) "Second Home"
    ["association_membership"]=>
    string(3) "Yes"
    ["serial_number"]=>
    string(13) "Serial Number"
    ["gender"]=>
    string(4) "Male"
    ["marital_status"]=>
    string(0) ""
    ["minors"]=>
    string(6) "Minors"
    ["base_price"]=>
    string(5) "259.7"
    ["used"]=>
    string(0) ""
    ["professional_cyclist"]=>
    string(0) ""
    ["triathlete"]=>
    string(0) ""
  }

Open in new window


On the page that I have included the function on, how do I grab and echo any of the items?  For example, how would I echo out the first one, ['row_id']
0
Comment
Question by:rgranlund
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 40622340
There are other parts to this, right?  There's a class definition, too?

It looks like there is a PDO data set in play here.  With PDO you get an array of arrays or objects in the results.  So the general design of the code goes something like this:

foreach ($order_items as $row)
{
    echo PHP_EOL . $row['row_id'];
}

Open in new window

0
 
LVL 34

Expert Comment

by:Slick812
ID: 40623335
greetings rgranlund, , I am Not understanding what you are asking with - "how do I grab and echo any of the items?", My main problem is tying this to your Question for EE as "Functions and variables", , grabbing an Item depends on Where you are writing code at that time,  You seem to already know what to do for code writes Inside of that function-method, so since you say "On the page that I have included the function on", I would guess that means writing code Outside of that function and outside of the Class Definition. But you may want to explain about what is giving you a problem with "Functions and variables".

If you are on the page,  your code might look something like -

    $ins = new insurance;
    $policyArray = $ins->policy_display( );
    echo "First Row, First Item is - ".$policyArray[0]["row_id"];

But I am not sure what coding problem you are asking about?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question