0

I've got a data feed I'm importing that has a load of 'markets', I want to have a main page displaying all the markets, so for that id use a foreach loop to go through the data and on each market make a listing.

Each market has a bunch of attributes as well as nested participants, I want to then make a page for each market, that displays some information about each participant.

So the user would navigate to index.php > event.php?id101

This is the bit were ive become stuck, how can i send the user to the right page, I was thinking of using

<?php 

$xml = simplexml_load_file('f1_feed.xml');


  foreach($xml->response->williamhill->class->type->market as $event) {
    $event_attributes = $event->attributes();
    echo "<tr>";

      // EVENT NAME WRAPPED IN LINK TO EVENT
      echo "<td>";
        echo '<a href="event.php?id=' . $market_id . '">';
            echo $event_attributes['name'];
        echo "</a>";
      echo"</td>";

      // DATE
      echo "<td>";
        echo $event_attributes['date'];
      echo "</td>";

    echo "</tr>";
  } 
?>

but how can I set a var $market_id (from the xml feed) to add to the end of the url, so it sends me to the right page ?

(f1_feed.xml is the same as the live xml feed, its just local for development)

the feed I'm using is http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=5&marketSort=HH&filterBIR=N

which im bring in using simplexml

2
  • Can you show some code you have done? Or you expect user here help you to solve everything? Commented Jan 24, 2013 at 18:42
  • @ajreal, sorry about, that please see the amended Commented Jan 24, 2013 at 19:08

1 Answer 1

1

This worked for me;

$xml = simplexml_load_file("openbet_cdn.xml");
foreach($xml->response->williamhill->class->type->market as $market) {
    // that gives an object (native)
    $market_attributes = $market->attributes();
    printf("<a href=\"event.php?id=%s\">%s</a>\n", 
                $market_attributes->id, 
                $market_attributes->name);
    // that gives an array (useless way!)
    // $market_attributes = (array) $market->attributes();
    // printf("<a href=\"event.php?id=%s\">%s</a>\n", 
                // $market_attributes['@attributes']['id'], 
                // $market_attributes['@attributes']['name']);
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for that, sorry for getting back to it so late. With you comment 'that gives the array (useless way!)' is that refering to the first $market_attributes block or the second ?
I mean don't use that part, just use oop part above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.