Combining two simplexml_load_file("xml")

Help Combining two simplexml_load_file(“xml”); 1 is random order of 15 and the other is ramdom by 5 to view total of 20 records in one list using PHP codes

here is the code for 1 xml

<div style="float:left; width:100%; padding-top:5px; padding-bottom:5px; text-align:center; background:#137cc0;">
	<span class="headerdark" style="color:#FFFFFF; font-size:18px;">Specialty</span>
	</div>
<?
		$specialty = simplexml_load_file("specialty.xml");
										
		$ctr = 0;
		$ctr1 = 0;
		$specialty_id = array();
		$specialty_name1 = array();
		$md_count1 = array();
		$option1 = array();
		foreach ($specialty as $spec) {
			$system_specialty_id = $spec->system_specialty_id;
			$specialty_name = $spec->specialty_name;
			$md_count = $spec->md_count;
			$option = $spec->option;
											
											
			//save to array
			$specialty_id[$ctr] = $system_specialty_id;
			$specialty_name1[$ctr] = $specialty_name;
			$md_count1[$ctr] = $md_count;
			$option1[$ctr] = $option;
			$ctr++;
		}
																
										
							
		$ctr2 = 0;
		$random_id = array_rand($specialty_id,15);
										
										
										
										
		while( $ctr2 < 15 ) {
											
			$system_specialty_id = $specialty_id[$random_id[$ctr2]];
			$specialty_name = $specialty_name1[$random_id[$ctr2]];
			$md_count = $md_count1[$random_id[$ctr2]];
			$option = $option1[$random_id[$ctr2]];
			$specialty_name3 = $specialty_name1[$random_id[$ctr2]];
																			
			if ($md_count!=0) {
				$clss = "linkspec";
			} else {
				$clss = "";
			}
			if ($md_count!=0) {
			if(strlen($specialty_name)>20){
			$specialty_name = substr($specialty_name,0,20).'...';
			} else {
			$specialty_name;
			}
											
			?>
										<div style="float:inherit; width:28%; display:table-row; margin-bottom:5px; margin-left:30px;margin-top:20px;">
                                        <div class="normal" style="display:table-cell; padding-right:5px;">
										<span style="color:#036ebc;">&#8226;</span></div> 
											<div class="normal" style="display:table-cell; line-height:15px;">                                                    
											<span class="<?=$clss?> normalblue15" id="<?=$system_specialty_id?>" title="<?=$specialty_name3?>">
                               				 <a><?=$specialty_name?></a></span>
                           					</div>
                              
                           					<div id="filter_<?=$system_specialty_id?>" class="filterspec" class="normal" style="display:none;padding:0;margin:0;display:none;text-align:center" align="center">
                     <? 
$locationselect = '<select name="dropdown" id="loc'.$system_specialty_id.'" class="form-control idurl" data-key="'.urlencode($specialty_name).'" data-keysearch="'.$specialty_name.'" onchange="urlLocChange('.$system_specialty_id.');" style="padding:5px; font-size:12px; color:#5B5B5B;background-color:#FF0; cursor:pointer;">';
      $locationselect .= '<option style="background-color:#FFF;" value="" disabled selected>Choose desired location:</option>';
								
								
foreach ($option->province as $child) {
	$province_name = $child;
	$province_id = $child->attributes();
	$locationselect .= "<option style='background-color:#FFF;' value='".$province_id."' data-loc='provid' data-prov='".$province_id."'>".$province_name."</option>";
	//echo $province_id. " - " . $province_name . "<br>";
	//for metro manila
		if($province_id==20070001){
			foreach ($option->city as $child) {
			$city_name = $child;
			$city_id = $child->attributes();
			//echo $city_id. " - " . $city_name . "<br>";
			$locationselect .= "<option style='background-color:#FFF;' value='".$city_id."' data-loc='cityid' data-prov='".$province_id."' ".$selected.">&nbsp;&nbsp;&nbsp;".$city_name."</option>";
		}
	}
}
$locationselect .= '</select>';
echo $locationselect;
                        ?>                           
                              
                                                           
                                                         
                                                </div>         
                                                     
													  </div>
                                                      <? }  ?>
                                                                                
												<?  
												
												?>
                                                
                                               </span>
														  
			<?
			$encodedid2='';
			if($newcc ==2|| $newrowhost==$newcon){
				$newcc=0;
			?></tr>
                                           
			<? }else{
				$newcc++;
			}?> 
                                             
			<? $ctr2++; ?>
                                          
<? } ?>
<?
echo'<div style="float:left; width:100%; padding:0px 0px 0px 0px; margin-left:30px;margin-top:20px;margin-bottom:10px;">';
		echo'<a href="doctor_search_category.php" class="health_condition_links" style="color:#5b5b5b; background:#f9f9f9; text-decoration:underline!important;">';
			echo"See all specialties";
		echo'</a>';
		echo'</div>';
?>

Can you edit that please to remove all the extra spacing, it’s way too difficult to read with all the sideway scrolling.

What exactly is the problem you are having? That is, what result do you need, and what does your code not do that it should, or do that it should not?

1 Like

<div style="float:left; width:100%; padding-top:5px; padding-bottom:5px; text-align:center; background:#137cc0;">
<span class="headerdark" style="color:#FFFFFF; font-size:18px;">Specialty</span>
</div>
<? $specialty = simplexml_load_file("specialty.xml");										
	$ctr = 0;
	$ctr1 = 0;
	$specialty_id = array();
	$specialty_name1 = array();
	$md_count1 = array();
	$option1 = array();
	foreach ($specialty as $spec) {
		$system_specialty_id = $spec->system_specialty_id;
		$specialty_name = $spec->specialty_name;
		$md_count = $spec->md_count;
		$option = $spec->option;
										
										
		//save to array
		$specialty_id[$ctr] = $system_specialty_id;
		$specialty_name1[$ctr] = $specialty_name;
		$md_count1[$ctr] = $md_count;
		$option1[$ctr] = $option;
		$ctr++;
	}
					
	$ctr2 = 0;
	$random_id = array_rand($specialty_id,15);
	while( $ctr2 < 15 ) {
											
	$system_specialty_id = $specialty_id[$random_id[$ctr2]];
	$specialty_name = $specialty_name1[$random_id[$ctr2]];
	$md_count = $md_count1[$random_id[$ctr2]];
	$option = $option1[$random_id[$ctr2]];
	$specialty_name3 = $specialty_name1[$random_id[$ctr2]];
																	
	if ($md_count!=0) {
		$clss = "linkspec";
	} else {
		$clss = "";
	}
	if ($md_count!=0) {
	if(strlen($specialty_name)>20){
	$specialty_name = substr($specialty_name,0,20).'...';
	} else {
	$specialty_name;
	}
									
	?>
    <div style="float:inherit; width:28%; display:table-row; margin-bottom:5px; margin-left:30px;margin-top:20px;">
    <div class="normal" style="display:table-cell; padding-right:5px;">
    <span style="color:#036ebc;">&#8226;</span></div> 
        <div class="normal" style="display:table-cell; line-height:15px;">                                                    
        <span class="<?=$clss?> normalblue15" id="<?=$system_specialty_id?>" title="<?=$specialty_name3?>">
         <a><?=$specialty_name?></a></span>
        </div>

        <div id="filter_<?=$system_specialty_id?>" class="filterspec" class="normal" style="display:none;padding:0;margin:0;display:none;text-align:center" align="center">
        <? $locationselect = '<select name="dropdown" id="loc'.$system_specialty_id.'" class="form-control idurl" data-key="'.urlencode($specialty_name).'" data-keysearch="'.$specialty_name.'" onchange="urlLocChange('.$system_specialty_id.');" style="padding:5px; font-size:12px; color:#5B5B5B;background-color:#FF0; cursor:pointer;">';
      $locationselect .= '<option style="background-color:#FFF;" value="" disabled selected>Choose desired location:</option>';					
foreach ($option->province as $child) {
	$province_name = $child;
	$province_id = $child->attributes();
	$locationselect .= "<option style='background-color:#FFF;' value='".$province_id."' data-loc='provid' data-prov='".$province_id."'>".$province_name."</option>";
		if($province_id==20070001){
			foreach ($option->city as $child) {
			$city_name = $child;
			$city_id = $child->attributes();
			$locationselect .= "<option style='background-color:#FFF;' value='".$city_id."' data-loc='cityid' data-prov='".$province_id."' ".$selected.">&nbsp;&nbsp;&nbsp;".$city_name."</option>";
		}
	}
}
$locationselect .= '</select>';
echo $locationselect; ?>                           
</div>         
</div>
<? }  ?>
</span>
<? $encodedid2='';
if($newcc ==2|| $newrowhost==$newcon){
	$newcc=0;
?></tr>
							   
<? }else{
	$newcc++;
}?>								 
<? $ctr2++; ?>                                          
<? } ?>
<? echo'<div style="float:left; width:100%; padding:0px 0px 0px 0px; margin-left:30px;margin-top:20px;margin-bottom:10px;">';
echo'<a href="doctor_search_category.php" class="health_condition_links" style="color:#5b5b5b; background:#f9f9f9; text-decoration:underline!important;">';
	echo"See all specialties";
echo'</a>';
echo'</div>'; ?>

Off Topic

@anonymousjames1515: when you post code on the forums, you need to format it so it will display correctly. (I’ve formatted the above code for you.)

You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.

Thanks for reformatting the code. I am still unclear on what the question is. What isn’t working, and can you narrow it down to a section of your code?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.