Solved

Functions and variables

Posted on 2015-02-20
2
93 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 110

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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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.

705 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