[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Functions and variables

Posted on 2015-02-20
2
Medium Priority
?
100 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 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

649 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