XML Sorting/Imploding HELP!

So i have a results page that is taking an XML feed, based on search critera (zip code, program, and location)…however i dont know how to add the ability to show results based on DEGREE LEVEL too.

I have the XML feed going into an array and the array imploding. I’m fairly new to php so examples and any tips are greatly appreciated.

Let me know if this is enough information you need to help resolve.

Thank you,

<?php


    $response = file_get_contents("http://www.xxxxx.com/page.php?id=1238&code=9dd46170bab569960ff4ae34fdb83f58&zip=$zip&career=$career&school_type=$school_type&program_type=$program_type");

$xml = simplexml_load_string($response);
$html = array(
              'Online' => array(),
              'Campus' => array(),
              'Other' => array(),
         );


foreach ($xml->capsule as $capsule) {
// Set $type var with ifs..

    if ($type == 'Online') {
    $capsule->city = 'Homestudy';
	$capsule->state = '(Online Program)';
    }
    if (empty($capsule->city)) {
    $capsule->city = 'Homestudy';
	$capsule->state = '(Online Program)';
}
if (empty($capsule->state)) {
    $capsule->city = 'Homestudy';
	$capsule->state = '(Online Program)';
}
foreach($capsule->program as $key => $program) {
	
	if (!empty($program_type) && $program_type != $program['program_type']) {
		unset($capsule->program[$key]);
 continue;
	}
	}

     if (isset($capsule->campus['type'])) {
              $type = trim($capsule->campus['type']);
         }
         else {
              $type = 'Other';
         }
$degree_level = "AS";
$program_list = null;
foreach($capsule->program as $program) {
  $program_list .= '<span class="blue">' . '<li>' . $program['program_type_name'] . ''. '</span> -
                     <span class="green">' . $program . '</li></span>';
}
$html[$type][] = '
             <div class="wrapper">
<div class="left_column"><a href="' . urldecode($capsule->link) . '&campaign_id=12616017&code=' . $source .''. '"><img src="' . urldecode($capsule->image) . ''. '" border="0" /></a></div>
<div align="center" class="central-colunm"><h2><b>' . urldecode($capsule->type) . '
                      <a href="' . urldecode($capsule->link) . '&campaign_id=12616017&code=' . $source .''. '">
                        ' . urldecode($capsule->form_name) . ''. '-' . $capsule->city . ''. ' ' . $capsule->state . ''. '</a></b><br />
  </h2></div>
<div class="right_column"><a href="' . urldecode($capsule->link) . '&campaign_id=12616017&code=' . $source .''. '"><a href="' . urldecode($capsule->link) . '&campaign_id=12616017&code=' . $source .''. '"><img src="images/learn_more.gif" border="0"
onmouseover="this.src=\\'images/learn_more_over.gif\\'"
onmouseout="this.src=\\'images/learn_more.gif\\'"></a></div>
<div class="central-colunm"><h4><a href="' . urldecode($capsule->link) . '&campaign_id=12616017&code=' . $source .''. '">DEGREE:(' . urldecode($program['program_type']) . ')</h4>
						  ' . $program_list . '

                            </h4>                     <br /></div>
<div class="spacer"></div>
</div>
';

    }


$ResultArray = array_slice($html['Online'], 0, 5);
//print_r($ResultArray);
//print_r($html);
print_r($program['program_type']);
if ($school_type == 'O') {
         echo implode('<b>Online School</b>', $ResultArray);
		 
		 
echo $html['Online']['As'];
    } else if ($school_type == 'C') {

         print implode('<b>Campus School</b>' , $html['Campus']);
         print implode('<b>Online School</b>' , $html['Online']);
    }
?>

What i am looking to do is have a form drop down (degree_level), and basically have the search critera pull only proper results. Right now its currently pulling ALL degree levels. I need to zoom in one more step and result only degrees that was selected.

the part of the XML capsule (capsule = each result as a capsule), $program[‘program_type’] will give you like “AS,BA, BS, MS, PhD” etc.
So i need to have the abiltiy to filter those results, i hope i’ve covered as much as i can in order for you guys to udnerstand.

Also, this loads DEATHLY slow - i’ve tried switching from tables to div results, using array_slice to limit results (so its not pulling 100 results), i’ve tried optomizing the html code on the page - still no avail. Is this just a SLOW xml feed? or is there something wrong with my code, that’s slowing it down?

recap:
Need to have ability to sort by $degree_level ($program[‘program_type’] is what the XML calls it), ALSO the XML uses like BA and BS both meaning Bachelor’s Degree, can i have 1 drop down option mean both BS and BA?
if possible, optmoize to speed up.

Thank you guys in advance,
Joey

Use XPath. :wink:


<?php
$xmlString = '<capsules>
  <capsule type="specific" client_id="2718" id="9633">
    <form_name>International Professional School of Bodywork</form_name>
    <city>San Diego</city>
    <state>CA</state>
    <distance>47</distance>
    <filter></filter>
    <image>http://www.xxx./logo/ipsb.gif</image>
    <link>http://www.xx;state=CA&amp;city=Temecula</link>
    <campus id="San Diego, CA" type="Campus">San Diego, CA</campus>
    <program id="Associate%20of%20Science%20in%20Holistic%20Health" program_type="AS" program_type_name="Associate">Associate of Science in Holistic Health</program>
    <program id="Essentials%20of%20Massage%20and%20Bodywork" program_type="AS" program_type_name="Associate">Essentials of Massage and Bodywork</program>
    <program id="Holistic%20Health%20Practitioner%20Program" program_type="AS" program_type_name="Associate">Holistic Health Practitioner Program</program>
    <program id="Massage%20Therapy%20Program" program_type="AS" program_type_name="Associate">Massage Therapy Program</program>
    <program id="Master%20of%20Arts%20in%20Somatics" program_type="MA" program_type_name="Master of Arts">Master of Arts in Somatics</program>
  </capsule>
</capsules>';

$xmlObj = new SimpleXMLElement($xmlString);

foreach($xmlObj->xpath("//program[@program_type='AS']") as $program){
  echo $program . chr(10);
}

/*
  Associate of Science in Holistic Health
  Essentials of Massage and Bodywork
  Holistic Health Practitioner Program
  Massage Therapy Program
*/

yeah the data changes VERY often.
i dont own the XML feed. i just have a XML parser that takes the data, puts it into “capsules” (each result).

Everything is perfect, except i cannot sort the results by degree_level aka $program[‘program_type’]

im not sure if i should filter that upon implode? or during the array? im very new to php and still dont understand alot of the concepts.

here is an example of the XML feed:

<capsule type="specific" client_id="2718" id="9633">
		<form_name>International Professional School of Bodywork</form_name>
		<city>San Diego</city>
		<state>CA</state>
		<distance>47</distance>
		<filter></filter>
		<image>http://www.xxx./logo/ipsb.gif</image>
		<link>http://www.xx;state=CA&#38;city=Temecula</link>
		<campus id="San Diego, CA" type="Campus">San Diego, CA</campus>
		<program id="Associate%20of%20Science%20in%20Holistic%20Health" program_type="AS" program_type_name="Associate">Associate of Science in Holistic Health</program>
		<program id="Essentials%20of%20Massage%20and%20Bodywork" program_type="AS" program_type_name="Associate">Essentials of Massage and Bodywork</program>
		<program id="Holistic%20Health%20Practitioner%20Program" program_type="AS" program_type_name="Associate">Holistic Health Practitioner Program</program>
		<program id="Massage%20Therapy%20Program" program_type="AS" program_type_name="Associate">Massage Therapy Program</program>
		<program id="Master%20of%20Arts%20in%20Somatics" program_type="MA" program_type_name="Master of Arts">Master of Arts in Somatics</program>

i just need like a FOREACH statement or something that will allow me to ONLY SHOW RESULTS THAT HAVE “program_type” == $degree_level.

its currently showing all results, i just need to filter out everything except whatever degree level was selected.

let me know if you need any other inforamtion, i really appreciate your time.

thank you

Unless this data is changing every minute or something, you should be caching (saving) the file locally so you can work on it.

Its probably going to help if you post here a single record from the xml file too (with correct head/tail).

So you are just trying to isolate, in your example this line, say:

<program id=“Master%20of%20Arts%20in%20Somatics” program_type=“MA” program_type_name=“Master of Arts”>Master of Arts in Somatics</program>

Because program_type is MA

Have I got it?