PHP 5: Return closest 5 results to a search value from an XML

nitrogen

New Member
I have an \[code\]XML\[/code\] which is supplied by a third party and I have no control over its formatting. It looks like this:\[code\]<base> <results index="1"> <quote vendor_name="Company X"> <quote_detail rate="3.375" price="-0.440"> <stuff>value</stuff> </quote_detail> </quote> </results> <results index="2"> <quote vendor_name="Company y"> <quote_detail rate="3.548" price="-0.230"> <stuff>value</stuff> </quote_detail> </quote> </results> <results index="3"> <quote vendor_name="Company Z"> <quote_detail rate="3.799" price="1.120"> <stuff>value</stuff> </quote_detail> </quote> </results> </base>\[/code\]What I need to do is return the result (\[code\]vendor_name\[/code\], \[code\]rate\[/code\] and \[code\]price\[/code\]) that has a price closest to zero without going over as well as the next two above and below. The ideal result would look something like this (where the middle one is closest to zero):[*]Company Z / 3.875 / -1.375[*]Company Y / 3.750 / -0.875[*]Company X / 3.375 / -0.440[*]Company A / 3.500 / 0.250[*]Company B / 3.375 / 1.125I'm not sure about the logic required to do this or how to preserve the \[code\]XML\[/code\] information while running said logic. Any help?
 
Back
Top