XPATH method for retuning multiple dynamic results from a XM

General discussions related to php

Moderators: macek, egami, gesf

Artfuldodger
New php-forum User
New php-forum User
Posts: 1
Joined: Sun May 19, 2013 3:18 am

XPATH method for retuning multiple dynamic results from a XM

Postby Artfuldodger » Sun May 19, 2013 4:33 am

I have a form that the user types or selects a value the form is as follows

Code: Select all

<form id="search_photos" action="photo_result.php" method="get">
   <input value="" name="photographer_id" id="photographer_id"  style=" border:1px solid Silver;" type="text">
   <select name="Photographer" id="Photographer"   style="height:23px; border:1px solid Silver;">
      <option selected="selected" value="x">Any Photographer</option>
      <option value="John">John</option>
      <option value="Fred">Fred</option>
      <option value="Joseph">Joseph</option>
   </select>
   <select name="images" id="images"   style="height:23px; border:1px solid Silver;">
      <option selected="selected" value="x">All Images</option>
      <option value="0">None</option>
      <option value="a">Image a</option>
      <option value="b">Image b </option>
      <option value="c">Image c </option>
   </select>
   <input name="Submit" value="Search Now &gt;" id="Submit" class="Adv1_Filter_Button" type="submit">
</form>

Then the search_photo.php script that catches the result of the form and filters the values entered by the user as follows

Code: Select all

<?php

   $xml = simplexml_load_file("photo.xml");
   
   for ($i = 0; $i < count($xml); $i++){ 
 
    if(isset($_GET["LocationName"]))
    {
        $photographer_id = $_GET["LocationName"];
    }
    $result = $xml->xpath('/root/area[photographer_id="' . $photographer_id . '"]  ');
   }
      
   if(isset($_GET["Photographer"]))
    {
        $photographer = $_GET["Photographer"];
    }
       $result = $xml->xpath('/root/area[photographer_id="' . $photographer_id . '"]  ');

   if(isset($_GET["images"]))
    {
        $image = $_GET["images"];
      
      
   }
       
    echo $photographer_id;
   echo $photographer;
   echo $image;
   var_dump ($result);
   
   ?>

The $result from the first XPATH pass is correct if all that is set is ‘photographer_id’ if I then try $result = $xml->xpath('/root/area[photographer_id="' . $photographer_id . '"] | /root/area[photographer="' . $photographer . '"]'); and select 1 and fred then I get the result of an array of all four when it should be an empty array
here is the XML file

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <area>
        <photographer_id>1</photographer_id>
        <photographer>John</photographer>
        <image>a</image>
    </area>
     <area>
        <photographer_id>1</photographer_id>
        <photographer>John</photographer>
        <image>b</image>
    </area>
     <area>
        <photographer_id>1</photographer_id>
        <photographer>John</photographer>
        <image>c</image>
    </area>
     <area>
        <photographer_id>2</photographer_id>
        <photographer>Fred</photographer>
        <image>a</image>
    </area>
</root>

any help greatly appreciated

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest