So i managed to find out the answer .. the if function need to be inserted inside the foreach function which i didnt put it before ..
?php
$productID = $_GET['product_id'];
$xml = simplexml_load_file("product.xml");
$searchedproduct = $xml->xpath('/products/product[product_id="'.$productID.'"]');
foreach($searchedproduct as $productinfo){
foreach ($productinfo as $productdetail){
if($productdetail->getName($image) == 'image_path'){
echo '<img src="'.$image.'" height="100"; "width="100" ;>';
}
else{
echo $productdetail->getName(). ": " ;
echo $productdetail . "<br/>";
}
}
}
?>
This is my XML file product.xml:
<product>
<category>Clothing</category>
<product_id>0236</product_id>
<title>Devon Denim Jacket</title>
<description>
</description>
<price>39.95 </price>
<image_path>product/nad/images/devon.jpg</image_path>
</product>
<product>
<category>Clothing</category>
<product_id>0238</product_id>
<title>Charlie Crew Fleece </title>
<description>
</description>
<price>24.95 </price>
<image_path>product/nad/images/graphic.jpg</image_path>
</product>
</products>