Solved

Functions and variables

Posted on 2015-02-20
2
81 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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

771 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

9 Experts available now in Live!

Get 1:1 Help Now