Solved

Functions and variables

Posted on 2015-02-20
2
87 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 108

Accepted Solution

by:
Ray Paseur earned 500 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 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

861 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now