Click to See Complete Forum and Search --> : [RESOLVED] simpleXML xpath and PHP = :(


marco_van_mayo
05-02-2006, 11:58 AM
hi. i am having a problem with SimpleXML, i was wondering if anybody could help.

this works...

foreach ($xml2->xpath('//appointments[cust_id = "mark"][date = "23-06-2006"]') as $app)

but this does not...

foreach ($xml2->xpath('//appointments[cust_id = "mark"][date = "$f_date2"]') as $app)

even though $f_date is 23-06-2006

NogDog
05-02-2006, 12:29 PM
Variables are not interpolated from within single-quote strings, so you'll need to use one of the following options:

foreach ($xml2->xpath("//appointments[cust_id = \"mark\"][date = \"$f_date2\"]") as $app)
// or //
foreach ($xml2->xpath("//appointments[cust_id = 'mark'][date = '$f_date2']") as $app)
// or //
foreach ($xml2->xpath('//appointments[cust_id = "mark"][date = "' . $f_date2 . '"]') as $app)

marco_van_mayo
05-02-2006, 12:51 PM
thanks for taking the time to have a look at my problem.. i had thought of the solutions that you have recommended but unfortunatly it didn't work.

marco_van_mayo
05-03-2006, 06:38 AM
actually i was just being a spaz.. it did work...

well done and thank you.. i owe a tiny bit of my degree to you