I'm trying to list the 10 most recent programs from my XML file (in a dropdown menu). In my PHP code, I'm having trouble accessing/echoing part of the attribute (ym) of the parent element (month) of each show.
XML:
PHP:
I'm trying to echo the month during which each program aired (11 or 10, based on the sample above). So the value of each option in the dropdown would have this format:
And so on... this is what I've tried that's close to what I need, but it keeps giving me "Array" instead of "11" or "10":
Thanks...
XML:
Code:
<?xml version="1.0" encoding="utf-8"?> <shows> <month ym="201411"> <show> <dt>26</dt> <wd>Wednesday</wd> </show> <show> <dt>25</dt> <wd>Tuesday</wd> </show> <!-- etc. --> </month> <month ym="201410"> <show> <dt>31</dt> <wd>Friday</wd> </show> <show> <dt>30</dt> <wd>Thursday</wd> </show> <!-- etc. --> </month> </shows>
Code:
$xml = simplexml_load_file("../../../programarchive.xml"); $show = $xml->xpath("//show"); $i = 0; while ($i<10) { echo "<option value='" . $show[$i]->wd . ", " . substr(PROBLEM IS HERE,-2) . "/" . $show[$i]->dt . "'>" . substr(PROBLEM IS HERE,-2) . "</option>\n\t\t\t\t\t\t"; $i++; }
Code:
<option value='Wednesday, 11/26'>Wednesday, 11/26</option> <option value='Tuesday, 11/25'>Tuesday, 11/25</option>
Code:
echo "<option value='" . $show[$i]->wd . ", " . $show[$i]->xpath("../@ym") . "/" . $show[$i]->dt . "'>" . $show[$i]->wd . ", " . $show[$i]->dt . "</option>\n\t\t\t\t\t\t";
Comment