• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

PHP XML

I'm trying to build a query that to me is a little complicated.  In my DB there are entries for products purchased.  Lets say John Doe has purchased three items.  There are three entries in DB.  Each entry contains First Name, Last Name, Age, Address Product Purchased, Size, Color, SKU. order ID number

All three entries have the same order id number.  I need to grab the Name, Age, Address once but need to loop through Products Purchased, Size, Color, SKU
Here is what I have so far but it is not correct.
$order_query = $this->EE->db->select('*')
					->from('cart_items')
					->where('order_id', $entry_id)
					->limit('1')
					->get();
$order_items = $order_query->result_array();

		$order_query->free_result();	
		$new_html= "<div class='container'>";
		
		foreach ($order_items as $row)
		{
			$this->nb_uuid = $this->generate_uuid();
			$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']);
			}
				
$fn = $row['first_name'];
$ln = $row['last_name'];
$age = $row['age'];
$address = $row['address'];
                        
$new_html.="<div class='labels'>".$fn."</div>";
$new_html.="<div class='labels'>".$ln."</div>";
$new_html.="<div class='labels'>".$address."</div>";
$new_html.="<div class='labels'>".$age."</div>";
}  //  END Foreach Loop

$order_query_b = $this->EE->db->select('*')
					->from('order_items')
					->where('order_id', $entry_id)
					->get();

	$order_items_b = $order_query_b->result_array();
	$order_query_b->free_result();

		foreach ($order_items_b as $row_b)
		{
			$this->nb_uuid_b = $this->generate_uuid();
			$extra_b = _unserialize($row_b['extra'], TRUE);
			
			if ($keep_extra)
			{
				$row_b['extra'] = $extra_b;
			}
			else
			{
				foreach ($extra_b as $key_b => $value_b)
				{
					if ( ! isset($row_b[$key_b]))
					{
						$row_b[$key_b] = $value_b;
					}
				}
				unset($row_b['extra']);
			}
$size = $row['size'];
$ln = $row['color'];
$age = $row['product'];
$address = $row['sku'];

$new_html.="<div class='labels'>Product".$product."</div>";
$new_html.="<div class='labels'>Color".$color."</div>";
$new_html.="<div class='labels'>Size".$size."</div>";
$new_html.="<div class='labels'>SKU".$sku."</div>";

} //  END Foreach loop

$new_html.= '</div>';

echo $new_html;

Open in new window


What I hope to see is:
<div class='container'>
<div class='labels'>John</div>
<div class='labels'>Doe</div>
<div class='labels'>45</div>
<div class='labels'>123 Test Lane</div>

<div class='labels'>Product: Shirt</div>
<div class='labels'>Color: Blue</div>
<div class='labels'>Size: Large</div>
<div class='labels'>SKU: 123</div>

<div class='labels'>Product: Pants</div>
<div class='labels'>Color: Red</div>
<div class='labels'>Size: Small</div>
<div class='labels'>SKU: 123</div>

<div class='labels'>Product: Shoes</div>
<div class='labels'>Color: Brown</div>
<div class='labels'>Size: XXL</div>
<div class='labels'>SKU: 3344</div>
</div>

Open in new window


But all I get is one iteration of the second loop.
<div class='container'>
<div class='labels'>John</div>
<div class='labels'>Doe</div>
<div class='labels'>45</div>
<div class='labels'>123 Test Lane</div>

<div class='labels'>Product: Shirt</div>
<div class='labels'>Color: Blue</div>
<div class='labels'>Size: Large</div>
<div class='labels'>SKU: 123</div>
</div>

Open in new window

0
rgranlund
Asked:
rgranlund
  • 6
  • 4
1 Solution
 
Slick812Commented:
greetings  rgranlund, , I can not see anything in this code about your subject as "PHP XML", but maybe the XML is something else?

I have some questions about your code? ?
You say that the second loop only does "One Iteration", but you do have a foreach LOOP that will loop until all the  arrays of rows in  $order_items_b  are done, so maybe there is just One row array in the  $order_items_b ? ? . . I have not seen php to just stop in a foreach loop unless   break;   is used

you seem to use the PHP    .=    correctly in your div writes as -
       $new_html.="<div class='labels'>Color".$color."</div>";
so I can not see that as a problem.


OOOHHHH, I just spotted the error, it is because you use -
    $size = $row['size'];
in the second foreach, should be
     $size = row_b['size'];

Using the $row , it is from the first query, so it never changes in the second foreach.
0
 
rgranlundAuthor Commented:
The $row/$row_b was a typo error on my part.  The code has $row_b in the second foreach  The first query, $order_items should only loop once and the order_items_b should loop three times.  This does not seem to be happening.
0
 
Slick812Commented:
I maybe should not say so, , but you do NOT need two query's to do this, it is a waste of DB access to do the same exact query twice (admittedly the first has a limit of One). . .
Instead just do ONE query, the second one in your code , , BUT add a line to echo the names, age and address, see code below -

$order_query_b = $this->EE->db->select('*')
					->from('order_items')
					->where('order_id', $entry_id)
					->get();

	$order_items_b = $order_query_b->result_array();
	$order_query_b->free_result();

	echo "<div class='labels'>".$order_query_b[0]['first_name']."</div>
<div class='labels'>".$order_query_b[0]['last_name']."</div>
<div class='labels'>".$order_query_b[0]['age']."</div>
<div class='labels'>".$order_query_b[0]['address']."</div>";

		foreach ($order_items_b as $row_b)
		{
			$this->nb_uuid_b = $this->generate_uuid();
			$extra_b = _unserialize($row_b['extra'], TRUE);
			
			if ($keep_extra)
			{
				$row_b['extra'] = $extra_b;
			}
			else
			{
				foreach ($extra_b as $key_b => $value_b)
				{
					if ( ! isset($row_b[$key_b]))
					{
						$row_b[$key_b] = $value_b;
					}
				}
				unset($row_b['extra']);
			}

$new_html.="<div class='labels'>Product".$row_b['product']."</div>";
$new_html.="<div class='labels'>Color".$row_b['color']."</div>";
$new_html.="<div class='labels'>Size".$row_b['size']."</div>";
$new_html.="<div class='labels'>SKU".$row_b['sku']."</div>";

} //  END Foreach loop

$new_html.= '</div>';

echo $new_html;

Open in new window



I could not test this code, but it should give you the idea for a way to do this.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
rgranlundAuthor Commented:
updated code:
$order_query = $this->EE->db->select('*')
					->from('cart_items')
					->where('order_id', $entry_id)
					->limit('1')
					->get();
$order_items = $order_query->result_array();

		$order_query->free_result();	
		$new_html= "<div class='container'>";
		
		foreach ($order_items as $row)
		{
			$this->nb_uuid = $this->generate_uuid();
			$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']);
			}
				
$fn = $row['first_name'];
$ln = $row['last_name'];
$age = $row['age'];
$address = $row['address'];
                        
$new_html.="<div class='labels'>".$fn."</div>";
$new_html.="<div class='labels'>".$ln."</div>";
$new_html.="<div class='labels'>".$address."</div>";
$new_html.="<div class='labels'>".$age."</div>";
}  //  END Foreach Loop

$order_query_b = $this->EE->db->select('*')
					->from('order_items')
					->where('order_id', $entry_id)
					->get();

	$order_items_b = $order_query_b->result_array();
	$order_query_b->free_result();

		foreach ($order_items_b as $row_b)
		{
			$this->nb_uuid_b = $this->generate_uuid();
			$extra_b = _unserialize($row_b['extra'], TRUE);
			
			if ($keep_extra)
			{
				$row_b['extra'] = $extra_b;
			}
			else
			{
				foreach ($extra_b as $key_b => $value_b)
				{
					if ( ! isset($row_b[$key_b]))
					{
						$row_b[$key_b] = $value_b;
					}
				}
				unset($row_b['extra']);
			}
$size = $row_b['size'];
$ln = $row_b['color'];
$age = $row_b['product'];
$address = $row_b['sku'];

$new_html.="<div class='labels'>Product".$product."</div>";
$new_html.="<div class='labels'>Color".$color."</div>";
$new_html.="<div class='labels'>Size".$size."</div>";
$new_html.="<div class='labels'>SKU".$sku."</div>";

} //  END Foreach loop

$new_html.= '</div>';

return $new_html;

Open in new window

0
 
Slick812Commented:
sorry I used the incorrect var  , , should be  $order_items_b[0]   , and NOT  $order_query_b[0] , so sorry.

 - - - - - - - - - -
If the  $row/$row_b was a typo error, and you have that in your code, then the only thing I see that can cause this is if you have only one row in the  $order_items_b, as I see nothing to prevent to loop from continuing until finish?

you might place a echo for the -
    count($order_items_b);
so you can get some trouble shooting info, for the number of entries in the $order_items_b array.
0
 
Slick812Commented:
there is an alternative the foreach LOOP using numbered arrays, like this

          for ($i = 0; $i < count($order_items_b); ++$i)  {
// then access the row elements with $order_items_b[$i]['extra'] -
          $extra_b = _unserialize($order_items_b[$i]['extra'], TRUE);


this is another way to try this, , but the foreach LOOP is dependable and has always worked for me.
0
 
rgranlundAuthor Commented:
The main issue I have with your one query example is that I must unserialize the return to get the Name Age etc...
0
 
rgranlundAuthor Commented:
I was simplifying my example so as to save time.  The following is the actual code.  Please be so kind as to have a quick look.

		$order_query = $this->EE->db->select('*')
					->from('exp_cartthrob_order_items')
					->where('order_id', $entry_id)
					->where('entry_id', '29')
					->limit('1')
					->get();

		$order_items = $order_query->result_array();

		$order_query->free_result();
		// setting $keep_extra here since it would throw an undefined error down below	
		
		$new_business_xml = "<PersInlandMarinePolicyRq>";
		
		foreach ($order_items as $row)
		{
			$this->nb_uuid = $this->generate_uuid();
			$extra = _unserialize($row['extra'], TRUE);
			
			// $keep_extra seems to be undefined, I'm going to set it to false up above so it writes out the row[$keys]
			if ($keep_extra)
			{
				$row['extra'] = $extra;
			}
			else
			{
				foreach ($extra as $key => $value)
				{
					if ( ! isset($row[$key]))
					{
						$row[$key] = $value;
					}
				}
				unset($row['extra']);
			}
				
			// going to go ahead and keep these variable names the way they came to me
			$policy_number = $row['policy_number'];
			$fn = $row['insured_first_name'];
			$ln = $row['insured_last_name'];
			$ma = $row['bicycle_location'];
			$ad = $row['location_address'];
			$ct = $row['location_city'];
			$st = $row['location_state'];
			$zip = $row['location_zip'];
			$email = $row['contact_email'];
			$gender = $row['gender'];
			$ms = $row['marital_status'];
			$min = $row['minors'];
			$ass = $row['association_membership'];
			$sd = date('Y-m-d', $row['entry_date']);
			$ed = date('Y-m-d', strtotime($sd . ' + 1 year'));
			$policy_total = $row['policy_total'];
	//echo"<pre>First Query<br />";
	//var_dump($extra);
	//echo"</pre>";
	//  exit;			
			// build out the New Business xml using the variables above
			
  $new_business_xml.= "<RqUID>".$this->nb_uuid."</RqUID>";
  $new_business_xml.= "<PolicyNbr>".$policy_number."</PolicyNbr>";
  $new_business_xml.= "<PolicyEffDt>".$sd."</PolicyEffDt>";
  $new_business_xml.= "<TransCd>NB</TransCd>";
  $new_business_xml.= "<TransEffDt>".$sd."</TransEffDt>";
  $new_business_xml.= "<TransIdentifier>1</TransIdentifier>";
  $new_business_xml.= "<PolicyIdentifier>".$policy_number."</PolicyIdentifier>";
  $new_business_xml.= "<DtiTransactionInfo>";
    $new_business_xml.= "<CreatedBy>".$this->order('username')."</CreatedBy>";
    $new_business_xml.= "<CreatedByName>".$fn." ".$ln."</CreatedByName>";
    $new_business_xml.= "<CreatedByEmail>".$email."</CreatedByEmail>";
  $new_business_xml.= "</DtiTransactionInfo>";
  $new_business_xml.= "<PersInlandMarinePolicy>";
    $new_business_xml.= "<Producer>";
      $new_business_xml.= "<ItemIdInfo>";
        $new_business_xml.= "<AgencyId>9000008S</AgencyId>";
      $new_business_xml.= "</ItemIdInfo>";
      $new_business_xml.= "<GeneralPartyInfo>";
        $new_business_xml.= "<NameInfo>";
          $new_business_xml.= "<CommlName>";
            $new_business_xml.= "<CommercialName>[9000008S] Marsh</CommercialName>";
          $new_business_xml.= "</CommlName>";
        $new_business_xml.= "</NameInfo>";
      $new_business_xml.= "</GeneralPartyInfo>";
      $new_business_xml.= "<ProducerInfo>";
        $new_business_xml.= "<ContractNumber>9000008S</ContractNumber>";
        $new_business_xml.= "<ProducerRoleCd>Agency</ProducerRoleCd>";
      $new_business_xml.= "</ProducerInfo>";
    $new_business_xml.= "</Producer>";
    $new_business_xml.= "<InsuredOrPrincipal>";
      $new_business_xml.= "<GeneralPartyInfo>";
        $new_business_xml.= "<NameInfo>";
          $new_business_xml.= "<PersonName>";
            $new_business_xml.= "<Surname>".$ln."</Surname>";
            $new_business_xml.= "<GivenName>".$fn."</GivenName>";
          $new_business_xml.= "</PersonName>";
        $new_business_xml.= "</NameInfo>";
        $new_business_xml.= "<Addr>";
          $new_business_xml.= "<AddrTypeCd>BillingAddress</AddrTypeCd>";
          $new_business_xml.= "<Addr1>".$this->order('address')."</Addr1>";
		  $new_business_xml.= "<Addr2>".$this->order('address2')."</Addr2>";
          $new_business_xml.= "<City>".$this->order('city')."</City>";
          $new_business_xml.= "<StateProvCd>".$this->order('state')."</StateProvCd>";
          $new_business_xml.= "<PostalCode>".$this->order('zip')."</PostalCode>";
        $new_business_xml.= "</Addr>";
        $new_business_xml.= "<Communications>";
          $new_business_xml.= "<PhoneInfo>";
            $new_business_xml.= "<PhoneNumber />";
          $new_business_xml.= "</PhoneInfo>";
          $new_business_xml.= "<EmailInfo id='EMail'>";
	    $new_business_xml.= "<CommunicationUseCd>".$ma."</CommunicationUseCd>";
            $new_business_xml.= "<EmailAddr>".$email."</EmailAddr>";
          $new_business_xml.= "</EmailInfo>";
        $new_business_xml.= "</Communications>";
      $new_business_xml.= "</GeneralPartyInfo>";
      $new_business_xml.= "<InsuredOrPrincipalInfo>";
        $new_business_xml.= "<InsuredOrPrincipalRoleCd>FNI</InsuredOrPrincipalRoleCd>";
	      $new_business_xml.= "<PersonInfo>";
	        $new_business_xml.= "<GenderCd>".$gender."</GenderCd>";
	        $new_business_xml.= "<MaritalStatusCd>".$ms."</MaritalStatusCd>";
            $new_business_xml.= "<MembershipInfo>";
              $new_business_xml.= "<MembershipId></MembershipId>";
              $new_business_xml.= "<MembershipTypeCd>".$ass."</MembershipTypeCd>";
            $new_business_xml.= "</MembershipInfo>";
	      $new_business_xml.= "</PersonInfo>";
      $new_business_xml.= "</InsuredOrPrincipalInfo>";
    $new_business_xml.= "</InsuredOrPrincipal>";
    $new_business_xml.= "<PersPolicy>";
      $new_business_xml.= "<ProgramIdentifier>Spoke</ProgramIdentifier>";	
      $new_business_xml.= "<PolicyNumber>".$policy_number."</PolicyNumber>";
      $new_business_xml.= "<WritingCompanyCd>Starr</WritingCompanyCd>";
      $new_business_xml.= "<LOBCd>INMRP</LOBCd>";
      $new_business_xml.= "<ControllingStateProvCd>".$st."</ControllingStateProvCd>";
      $new_business_xml.= "<ContractTerm>";
        $new_business_xml.= "<EffectiveDt>".$sd."</EffectiveDt>";
        $new_business_xml.= "<ExpirationDt>".$ed."</ExpirationDt>";
      $new_business_xml.= "</ContractTerm>";
      $new_business_xml.= "<CurrentTermAmt>";
        $new_business_xml.= "<Amt>".$this->total()."</Amt>";
      $new_business_xml.= "</CurrentTermAmt>";
      $new_business_xml.= "<WrittenAmt>";
        $new_business_xml.= "<Amt>".$this->total()."</Amt>";
        $new_business_xml.= "<CurCd>USD</CurCd>";
      $new_business_xml.= "</WrittenAmt>";
     $new_business_xml.= " <NetChangeAmt>";
         $new_business_xml.= "<Amt>".$this->total()."</Amt>";
      $new_business_xml.= "</NetChangeAmt>";
      $new_business_xml.= "<PurePremiumAmt>";
        $new_business_xml.= "<Amt>".$this->total()."</Amt>";
        $new_business_xml.= "<CurCd>USD</CurCd>";
      $new_business_xml.= "</PurePremiumAmt>";
     $new_business_xml.= " <PureWrittenAmt>";
        $new_business_xml.= "<Amt>".$this->total()."</Amt>";
        $new_business_xml.= "<CurCd>USD</CurCd>";
      $new_business_xml.= "</PureWrittenAmt>";
      $new_business_xml.= "<PureChgAmt>";
        $new_business_xml.= "<Amt>".$this->total()."</Amt>";
        $new_business_xml.= "<CurCd>USD</CurCd>";
      $new_business_xml.= "</PureChgAmt>";
      $new_business_xml.= "<TaxesSurchargesAmt>";
        $new_business_xml.= "<Amt></Amt>";
      $new_business_xml.= "</TaxesSurchargesAmt>";
      $new_business_xml.= "<PolicyTermCd>12</PolicyTermCd>";
      $new_business_xml.= "<PolicyStatusCd>ISSUED</PolicyStatusCd>";
    $new_business_xml.= "</PersPolicy>";
    $new_business_xml.= "<CreditOrSurcharge>";
      $new_business_xml.= "<CreditSurchargeCd>XX1</CreditSurchargeCd>";
      $new_business_xml.= "<NumericValue>";
        $new_business_xml.= "<FormatCurrencyAmt>";
          $new_business_xml.= "<Amt>0</Amt>";
        $new_business_xml.= "</FormatCurrencyAmt>";
      $new_business_xml.= "</NumericValue>";
      $new_business_xml.= "<CategoryCd>Surcharge</CategoryCd>";
    $new_business_xml.= "</CreditOrSurcharge>";
    $new_business_xml.= "<Location id='d73cb58d-0ea6-49fe-8004-d2a3c25d84f8'>";
      $new_business_xml.= "<ItemIdInfo>";
        $new_business_xml.= "<OtherIdentifier>";
          $new_business_xml.= "<OtherIdTypeCd>LOCNBR</OtherIdTypeCd>";
          $new_business_xml.= "<OtherId>1</OtherId>";
        $new_business_xml.= "</OtherIdentifier>";
      $new_business_xml.= "</ItemIdInfo>";
      $new_business_xml.= "<Addr>";
        $new_business_xml.= "<AddrTypeCd>StreetAddress</AddrTypeCd>";
        $new_business_xml.= "<Addr1>".$ad."</Addr1>";
        $new_business_xml.= "<City>".$ct."</City>";
        $new_business_xml.= "<StateProvCd>".$st."</StateProvCd>";
        $new_business_xml.= "<PostalCode>".$zip."</PostalCode>";
        $new_business_xml.= "<County></County>";
      $new_business_xml.= "</Addr>";
      $new_business_xml.= "<LocationDesc>".$ma."</LocationDesc>";
      $new_business_xml.= "<TaxCity>Not Listed</TaxCity>";
      $new_business_xml.= "<TaxCounty>Not Listed</TaxCounty>";
       $new_business_xml.= "</Location>";
       
			
	
	$order_query_b = $this->EE->db->select('*')
					->from('exp_cartthrob_order_items')
					->where('order_id', $entry_id)
					->where('entry_id', '29')
					->get();

	$order_items_b = $order_query_b->result_array();

	$order_query_b->free_result();
		// setting $keep_extra here since it would throw an undefined error down below
		
		
		foreach ($order_items_b as $row_b)
		{
			$this->nb_uuid_b = $this->generate_uuid();
			$extra_b = _unserialize($row_b['extra'], TRUE);
			
			// $keep_extra seems to be undefined, I'm going to set it to false up above so it writes out the row[$keys]
			if ($keep_extra)
			{
				$row_b['extra'] = $extra_b;
			}
			else
			{
				foreach ($extra_b as $key_b => $value_b)
				{
					if ( ! isset($row_b[$key_b]))
					{
						$row_b[$key_b] = $value_b;

					}
				}
				unset($row_b['extra']);
			}
				
			// going to go ahead and keep these variable names the way they came to me
			$pro = $row_b['professional_cyclist'];
			$tri = $row_b['triathlete'];
			$bike_type = $row_b['type_bicycle'];
			$manufacturer = $row_b['manufacturer'];
			$year = $row_b['year_built'];
			$model = $row_b['model'];
			$purdate = $row_b['purchase_date'];
			$purpri = $row_b['purchase_price'];
			$sn = $row_b['serial_number'];
			$bike_value = $row_b['bike_value'];
			$accessories_value = $row_b['accessories_value'];
			$bt = $row_b['type_bicycle'];
			$bmt = $row_b['bicycle_material'];
			$usage = $row_b['usage'];
			$total_value = $row_b['bike_value'];
			$product_deductible = $row_b['physical_damage_total'];
			$deductible_amount = $row_b['deductible_option_name'];
			$product_liabel = $row_b['liability_option_name'];
			$liabel_amount = $row_b['liability_total'];
			$product_medical = $row_b['medical_option_name'];
			$medical_amount = $row_b['medical_total'];
			$product_vehicle = $row_b['vehicle_option_name'];
			$vehicle_total = $row_b['vehicle_total'];
	//echo"<pre>Second Query<br />";
	//var_dump($extra_b);
	//echo"</pre>";
  //  exit;		
			// build out the New Business xml using the variables above
    
  ////PER Bike
    
    $new_business_xml.= "<PersInlandMarineLineBusiness>";
      $new_business_xml.= "<LOBCd>INMRP</LOBCd>";               
      $new_business_xml.= "<PropertySchedule id='".$this->nb_uuid_b."' LocationRef='d73cb58d-0ea6-49fe-8004-d2a3c25d84f8'>";
	$new_business_xml.= "<IsSummaryInd>N</IsSummaryInd>";
        $new_business_xml.= "<ItemIdInfo>";
          $new_business_xml.= "<OtherIdentifier>";
            $new_business_xml.= "<OtherIdTypeCd>".$bike_type."</OtherIdTypeCd>";
            $new_business_xml.= "<OtherId>".$count."</OtherId>";
          $new_business_xml.= "</OtherIdentifier>";
        $new_business_xml.= "</ItemIdInfo>";
        $new_business_xml.= "<ItemDefinition>";
          $new_business_xml.= "<ItemTypeCd>ScheduledProperty</ItemTypeCd>";
          $new_business_xml.= "<Manufacturer>".$manufacturer."</Manufacturer>";
          $new_business_xml.= "<Model>".$model."</Model>";
          $new_business_xml.= "<SerialIdNumber>".$sn."</SerialIdNumber>";
          $new_business_xml.= "<ModelYear>".$year."</ModelYear>";
         $new_business_xml.= " <ItemDesc>".$bmt."</ItemDesc>";
       $new_business_xml.= " </ItemDefinition>";
        $new_business_xml.= "<ItemValuationTypeCd>BicycleValue</ItemValuationTypeCd>";
        $new_business_xml.= "<ItemValueAmt>";
		$new_business_xml.= "<Amt>".$bike_value."</Amt>";
       $new_business_xml.= " </ItemValueAmt>";
        $new_business_xml.= "<PropertyClassCd></PropertyClassCd>";
       $new_business_xml.= " <ValuationTypeCd></ValuationTypeCd>";
        $new_business_xml.= "<Coverage>";
         $new_business_xml.= " <CoverageCd>1811</CoverageCd>";
          $new_business_xml.= "<CoverageDesc>Personal Property Damage</CoverageDesc>";
          $new_business_xml.= "<Limit>";
            $new_business_xml.= "<FormatCurrencyAmt>";
              $new_business_xml.= "<Amt>".$bike_value."</Amt>";
            $new_business_xml.= "</FormatCurrencyAmt>";
            $new_business_xml.= "<LimitAppliesToCd>Coverage</LimitAppliesToCd>";
          $new_business_xml.= "</Limit>";
          $new_business_xml.= "<Limit>";
            $new_business_xml.= "<FormatCurrencyAmt>";
              $new_business_xml.= "<Amt>".$accessories_value."</Amt>";
            $new_business_xml.= "</FormatCurrencyAmt>";
            $new_business_xml.= "<LimitAppliesToCd>Prop</LimitAppliesToCd>";
          $new_business_xml.= "</Limit>";
          $new_business_xml.= "<Deductible>";
            $new_business_xml.= "<FormatCurrencyAmt>";
              $new_business_xml.= "<Amt>".$deductible_amount."</Amt>";
            $new_business_xml.= "</FormatCurrencyAmt>";
          $new_business_xml.= "</Deductible>";
         $new_business_xml.= "<CurrentTermAmt>";
            $new_business_xml.= "<Amt>".$product_deductible."</Amt>";
          $new_business_xml.= "</CurrentTermAmt>";
          $new_business_xml.= "<WrittenAmt>";
            $new_business_xml.= "<Amt>".$product_deductible."</Amt>";
            $new_business_xml.= "<CurCd>USD</CurCd>";
          $new_business_xml.= "</WrittenAmt>";
          $new_business_xml.= "<NetChangeAmt>";
            $new_business_xml.= "<Amt>".$product_deductible."</Amt>";
          $new_business_xml.= "</NetChangeAmt>";
        $new_business_xml.= "</Coverage>";
        $new_business_xml.= "<Coverage>";
          $new_business_xml.= "<CoverageCd>1812</CoverageCd>";
          $new_business_xml.= "<CoverageDesc>Personal Liability</CoverageDesc>";
          $new_business_xml.= "<Limit>";
            $new_business_xml.= "<FormatCurrencyAmt>";
              $new_business_xml.= "<Amt>".$product_liabel."</Amt>";
            $new_business_xml.= "</FormatCurrencyAmt>";
          $new_business_xml.= "</Limit>";
          $new_business_xml.= "<CurrentTermAmt>";
            $new_business_xml.= "<Amt>".$liabel_amount."</Amt>";
          $new_business_xml.= "</CurrentTermAmt>";
          $new_business_xml.= "<WrittenAmt>";
            $new_business_xml.= "<Amt>".$liabel_amount."</Amt>";
            $new_business_xml.= "<CurCd>USD</CurCd>";
          $new_business_xml.= "</WrittenAmt>";
          $new_business_xml.= "<NetChangeAmt>";
            $new_business_xml.= "<Amt>".$liabel_amount."</Amt>";
          $new_business_xml.= "</NetChangeAmt>";
          $new_business_xml.= "<CreditOrSurcharge/>";
          $new_business_xml.= "<EffectiveDt/>";
          $new_business_xml.= "<ExpirationDt/>";
          $new_business_xml.= "<Rate/>";
          $new_business_xml.= "<PremiumBasisCd/>";
          $new_business_xml.= "<RatingClassificationCd></RatingClassificationCd>";
        $new_business_xml.= "</Coverage>";
	      $new_business_xml.= "<Coverage>";
          $new_business_xml.= "<CoverageCd>1813</CoverageCd>";
          $new_business_xml.= "<CoverageDesc>Personal Medical Expense</CoverageDesc>";
          $new_business_xml.= "<Limit>";
           $new_business_xml.= "<FormatCurrencyAmt>";
             $new_business_xml.= " <Amt>".$product_medical."</Amt>";
            $new_business_xml.= "</FormatCurrencyAmt>";
          $new_business_xml.= "</Limit>";
          $new_business_xml.= "<CurrentTermAmt>";
            $new_business_xml.= "<Amt>".$medical_amount."</Amt>";
          $new_business_xml.= "</CurrentTermAmt>";
          $new_business_xml.= "<WrittenAmt>";
            $new_business_xml.= "<Amt>".$medical_amount."</Amt>";
            $new_business_xml.= "<CurCd>USD</CurCd>";
          $new_business_xml.= "</WrittenAmt>";
          $new_business_xml.= "<NetChangeAmt>";
            $new_business_xml.= "<Amt>".$medical_amount."</Amt>";
          $new_business_xml.= "</NetChangeAmt>";
          $new_business_xml.= "<CreditOrSurcharge/>";
          $new_business_xml.= "<EffectiveDt/>";
          $new_business_xml.= "<ExpirationDt/>";
          $new_business_xml.= "<Rate/>";
          $new_business_xml.= "<PremiumBasisCd/>";
          $new_business_xml.= "<RatingClassificationCd></RatingClassificationCd>";
        $new_business_xml.= "</Coverage>";
        $new_business_xml.= "<Coverage>";
          $new_business_xml.= "<CoverageCd>1849</CoverageCd>";
          $new_business_xml.= "<CoverageDesc>Motor Vehicle Contact Liability</CoverageDesc>";
          $new_business_xml.= "<Limit>";
            $new_business_xml.= "<FormatCurrencyAmt>";
              $new_business_xml.= "<Amt>".$product_vehicle."</Amt>";
            $new_business_xml.= "</FormatCurrencyAmt>";
          $new_business_xml.= "</Limit>";
          $new_business_xml.= "<CurrentTermAmt>";
            $new_business_xml.= "<Amt>".$vehicle_total."</Amt>";
          $new_business_xml.= "</CurrentTermAmt>";
          $new_business_xml.= "<WrittenAmt>";
            $new_business_xml.= "<Amt>".$vehicle_total."</Amt>";
            $new_business_xml.= "<CurCd>USD</CurCd>";
          $new_business_xml.= "</WrittenAmt>";
          $new_business_xml.= "<NetChangeAmt>";
            $new_business_xml.= "<Amt>".$vehicle_total."</Amt>";
          $new_business_xml.= "</NetChangeAmt>";
          $new_business_xml.= "<CreditOrSurcharge/>";
          $new_business_xml.= "<EffectiveDt/>";
          $new_business_xml.= "<ExpirationDt/>";
          $new_business_xml.= "<Rate/>";
          $new_business_xml.= "<PremiumBasisCd/>";
          $new_business_xml.= "<RatingClassificationCd></RatingClassificationCd>";
        $new_business_xml.= "</Coverage>";
        $new_business_xml.= "<Coverage>";
          $new_business_xml.= "<CoverageCd>1850</CoverageCd>";
          $new_business_xml.= "<CoverageDesc>Roadside Assistance</CoverageDesc>";
          $new_business_xml.= "<Limit>";
            $new_business_xml.= "<FormatInteger>1</FormatInteger>";
          $new_business_xml.= "</Limit>";
         $new_business_xml.= " <Deductible/>";
          $new_business_xml.= "<CurrentTermAmt>";
            $new_business_xml.= "<Amt>10</Amt>";
          $new_business_xml.= "</CurrentTermAmt>";
          $new_business_xml.= "<WrittenAmt>";
            $new_business_xml.= "<Amt>10</Amt>";
            $new_business_xml.= "<CurCd>USD</CurCd>";
          $new_business_xml.= "</WrittenAmt>";
          $new_business_xml.= "<NetChangeAmt>";
            $new_business_xml.= "<Amt>10</Amt>";
          $new_business_xml.= "</NetChangeAmt>";
          $new_business_xml.= "<CreditOrSurcharge/>";
          $new_business_xml.= "<EffectiveDt/>";
          $new_business_xml.= "<ExpirationDt/>";
          $new_business_xml.= "<Rate/>";
          $new_business_xml.= "<PremiumBasisCd/>";
          $new_business_xml.= "<RatingClassificationCd></RatingClassificationCd>";
        $new_business_xml.= "</Coverage>";
        $new_business_xml.= "<SalesReceiptAppraisal>";
          $new_business_xml.= "<SalesReceiptAppraisalAmt><Amt>".$purpri."</Amt></SalesReceiptAppraisalAmt>";
          $new_business_xml.= "<SalesReceiptAppraisalDt>".$purdate."-01-01</SalesReceiptAppraisalDt>";
          $new_business_xml.= "<SalesReceiptAppraisalTypeCd>SaleRec</SalesReceiptAppraisalTypeCd>";
        $new_business_xml.= "</SalesReceiptAppraisal>";
        $new_business_xml.= "<UsageCd>".$usage."</UsageCd>";
      $new_business_xml.= "</PropertySchedule>";
      $new_business_xml.= "<QuestionAnswer id='Q000'>";
        $new_business_xml.= "<QuestionCd>Triathlete</QuestionCd>";
        $new_business_xml.= "<YesNoCd>".$tri."</YesNoCd>";
        $new_business_xml.= "<Explanation>Are you a triathlete?</Explanation>";
      $new_business_xml.= "</QuestionAnswer>";
      $new_business_xml.= "<QuestionAnswer id='Q001'>";
        $new_business_xml.= "<QuestionCd>Professional</QuestionCd>";
        $new_business_xml.= "<YesNoCd>".$pro."</YesNoCd>";
        $new_business_xml.= "<Explanation>Are you a professional cyclist?</Explanation>";
      $new_business_xml.= "</QuestionAnswer>";
    $new_business_xml.= "</PersInlandMarineLineBusiness>"; 
	$count++;	
	}  //  END Foreach Loop of each New Business Call
    //echo"<pre>Second Query, Bike Repeat<br />";
  // var_dump($order_query_b);
  }
   //echo"</pre>";
   	$new_business_xml.= "  </PersInlandMarinePolicy>";
	$new_business_xml.= "</PersInlandMarinePolicyRq>";
	

Open in new window

0
 
Slick812Commented:
OK,  If this is the actual code you use? ? I can see what looks to me to be an error in coding -
On your Line #196 you start your second Query, and I see NO  }  above it to contain (bracket) the first foreach as -
          foreach ($order_items as $row)
            {

I would think you should have a  }   on line #194 to close that one, then you will need to remove the last    }  in your code.

I have looked , again and again, but I see NOTHING in your second foreach LOOP -
           foreach ($order_items_b as $row_b)
            {

that might cause it to exit after only ONE run. I just can not find a problem in that second foreach.
since this seems to be writting a TEXT XML, you might really reduce the code in this, and see if you can get it to work th second loop with a minimum of test code.
0
 
Slick812Commented:
I can see your commented trouble shooting code like -
         //echo"<pre>Second Query<br />";
      //var_dump($extra_b);
      //echo"</pre>";

and -
     //echo"<pre>Second Query, Bike Repeat<br />";
     // var_dump($order_query_b);
    }
    //echo"</pre>";

so I guess that these outputs when used, (un commented), also showed that your second foreach loop, only did one iteration , , AND most important that the  $order_items_b   has more than ONE row in it? And so you are here for a fix.

I have done many many text string builds in mysqli ROW loops with code like -
       $new_business_xml.= "<OtherIdTypeCd>".$bike_type."</OtherIdTypeCd>";
I usually use the ROW variable like -
       $new_business_xml.= "<OtherIdTypeCd>".$row_b['type_bicycle']."</OtherIdTypeCd>";
which reduces code and reduces trouble shooting for me,

BUT if these unbroken HTML or XML are very long, as yours is here, with over 100 of  
    $new_business_xml.=
then I can not really see what my result XML string is about because it's so long in my text editor,
It greatly helps me in development to add text line breaks (and or tabs) at text section separations, you might add two line breaks at your first    $new_business_xml.=    in the second foreach loop, like -

////PER Bike
   
    $new_business_xml.= "

<PersInlandMarineLineBusiness>";

that way when you inspect the XML string in the same text editor that you wrote the code in, then all of the separate iterations will be on a separate new line, and can be more easy to analyze.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now