1

Thanks to your site and its helpful members I am almost completely finished with this project apart from one little problem .

Background ..

I have a form that enters data to an xml file and a page that displays the information based on 2 pieces of criteria it needs to match today's date and have the status out .

Problem is the code I am using gives me the data when it matches only status and not both I need it to match both before showing the data .

XML Structure ....

<information> <entry> <date></date> <name></name> <status></status> <notes></notes> <comments></comments> </entry> </information> 

Code For Retrieving And Displaying Data ...

$lib = simplexml_load_file("sample.xml"); $today = date('m/d/y'); $query = $lib->xpath("//entry[.//date[contains(., ' $today')]]|//entry[.//status[contains(., 'out')]]"); if( $query ) { foreach($query as $node){ echo "<div id='one'>$node->name</div> <div id='two'>$node->notes</div> <div id='three'><div class='front'>$node->comments</div></div>"; } } else { // Echo the special div. } 

So as you can see from the code I have it querying whether or not it contains today's date via the $today function (which is not working ) and querying whether or not it contains out in status but as of yet I can not get it to work to match both it only matches status.

I apologise if this has been answered somewhere before and I thank you all in advance for any help given on this matter . I also apologise if the question is too vague or I have not been forthcoming enough with details .

2
  • You don't need the echo in the Xpath Commented Jan 22, 2014 at 22:12
  • Sorry that was me trying it that was not there in first place still does not work either way Commented Jan 22, 2014 at 22:20

1 Answer 1

1

the | in your xpath-expression means or, try this instead:

... xpath("/information/entry[date = '01/23/2014' and status='out']") 

It will work great without the contains() on

<date>01/23/2014</date> <status>out</status> 

use this

... xpath("/information/entry[date[contains(., '01/23/2014')] and status[contains(., 'out')]]") 

on this:

<date>foo01/23/2014</date> <status>barout</status> 

see it working: https://eval.in/93642

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your reply and it will no doubt solve the original question . I do not know if you could help with the updated question ? Any help would be greatly received . Basically it looks like $today variable is not being seen or used and not matching up to date .
After re reading after much needed tea and applying your code this finally works thank you so very much you are a complete star when I have enough reputation you can be sure that I will up 1 your answer .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.