I have a created a small query search for a xml file my problem is that when search with the photographer_id selected as it is a number ie 1,2,3 ect I get the rong result but if I change the form and xml file from 1 to one and 2 to two the search works fine I have tries casting the values from the get request and photographer_id to an integer with (int) and is numeric but same results
$xml = simplexml_load_file("photo.xml");
for ($i = 0; $i < count($xml); $i++){
if(isset($_GET["LocationName"]))
{
$photographer = $_GET["LocationName"];
}
$result = $xml->xpath('/root/area[photographer="' . $photographer . '"] ');
}
if(isset($_GET["photographer_id"]))
{
$photographer_id = $_GET["photographer_id"];
}
if(isset($_GET["images"]))
{
$image = $_GET["images"];
}
//echo $photographer_id;
//echo $photographer;
//echo $image;
$filteredResult = array();
foreach($result as $obj){
if(in_array($photographer_id, (array)$obj) || $photographer_id == 'x'){
if(in_array($image, (array)$obj) || $image == 'x'){
array_push($filteredResult, $obj);
}
}
}
foreach($filteredResult as &$obj){
//how to access values in the object
//echo $obj->{'photographer'};
echo $obj->{'image'};
}
if (empty($filteredResult)) {
echo 'Empty';
}
I have tried debug this piece of code but still can't figure out where I am going wrong
<?xml version="1.0" encoding="UTF-8"?>
<root>
<area>
<photographer_id>1</photographer_id>
<photographer>John</photographer>
<image>a</image>
<image_id>1</image_id>
</area>
<area>
<photographer_id>1</photographer_id>
<photographer>John</photographer>
<image>b</image>
<image_id>2</image_id>
</area>
<area>
<photographer_id>1</photographer_id>
<photographer>John</photographer>
<image>c</image>
<image_id>3</image_id>
</area>
<area>
<photographer_id>2</photographer_id>
<photographer>Fred</photographer>
<image>a</image>
<image_id>4</image_id>
</area>
<area>
<photographer_id>3</photographer_id>
<photographer>Joseph</photographer>
<image>a</image>
<image_id>5</image_id>
</area>
</root>
this question is not about XPATH, the XPATH search works fine its about why the search query 'one' returns correctly and yet if '1' is used the search pattern is incorrect