Jump to content

dietkinnie

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Everything posted by dietkinnie

  1. Hi Guys, I would like to add an Order number/s to the parsed xml code below. <game id="3664066" date="20090325" time="1700"> <description> <category id="SOCMENEURESPSEGB1" order="7200">Spa. Segunda B1</category>Celta B - Valladolid B</description> <type id="0"/> <alternatives> <alternative odds="1.50" team="133702">1</alternative> <alternative odds="3.50" team="133702">X</alternative> <alternative odds="5.95" team="193111">2</alternative> </alternatives> </game> <game id="3664073" date="20090325" time="1700"> <description> <category id="SOCMENEURESPSEGB1" order="7200">Spa. Segunda B1</category>Deportivo B - Athletic B</description> <type id="0"/> <alternatives> <alternative odds="2.70" team="133707">1</alternative> <alternative odds="2.85" team="133707">X</alternative> <alternative odds="2.50" team="193120">2</alternative> </alternatives> </game> Here is my code: $xml = new SimpleXMLElement($source,null,true); foreach($xml->game as $game) { $game_id = $game['id']; foreach($game->type as $type){ $type_id = $type['id']; foreach($game->alternatives->alternative as $alt_odd){ $odds = $alt_odd['odds']; $team = $alt_odd['team']; echo "{$game_id} - {$odds} - {$team} - {$alt_odd} - {$type_id}<br>"; } } } ?> And here is the output: 3664066 - 1.50 - 133702 - 1 - 0 3664066 - 3.50 - 133702 - X - 0 3664066 - 5.95 - 193111 - 2 - 0 3664073 - 2.70 - 133707 - 1 - 0 3664073 - 2.85 - 133707 - X - 0 3664073 - 2.50 - 193120 - 2 - 0 As you can see there are two game_id's 3664066 and 3664073 respectively. These games however have 3 alternatives 1 or X or 2. I would like to add an order to each game id so it should look something like this: 3664066 - 1.50 - 133702 - 1 - 0 - 1 3664066 - 3.50 - 133702 - X - 0 - 2 3664066 - 5.95 - 193111 - 2 - 0 - 3 3664073 - 2.70 - 133707 - 1 - 0 - 1 3664073 - 2.85 - 133707 - X - 0 - 2 3664073 - 2.50 - 193120 - 2 - 0 - 3 Where the order starts over again for each new game id. Any tips would be greatly appreciated. Thanks in advance.
  2. Hi Guys, Can anyone help me figure this out, if possible ? I need to split the following: Peter - Jane: High/Low To $var1 = peter $var2 = Jane $var3 = High/Low Thanks in advance.
  3. Infact this is a different problem Taking the below xml into consideration <game id="3664066" date="20090325" time="1700"> − <description> <category id="SOCMENEURESPSEGB1" order="7200">Spa. Segunda B1</category> Celta B - Valladolid B </description> <type id="0"/> − <alternatives> <alternative odds="1.50" team="133702">1</alternative> <alternative odds="3.50" team="133702">X</alternative> <alternative odds="5.95" team="193111">2</alternative> </alternatives> </game> This should be the output: where the game id is common , odds are respective to bet type i.e (1 or X or 2 ) 3664066 - 1.50 - 133702 - 1 3664066 - 3.50 - 133707 - X 3664066 - 5.95 - 193144 - 2
  4. Hi Dj Kat, First of all thanks for your swift reply. Now i seem to have run into another problem. Here is the code. $xml = new SimpleXMLElement($source,null,true); foreach($xml->game as $game) { $game_id = $game['id']; $odds = $game->alternatives->alternative['odds']; $team = $game->alternatives->alternative['team']; foreach($game->alternatives->alternative as $alternatives){ echo "{$game_id} - {$odds} - {$team} - {$alternatives}<br>"; } } ?> And here is the output: 3664066 - 1.50 - 133702 - 1 3664066 - 1.50 - 133702 - X 3664066 - 1.50 - 133702 - 2 3664073 - 2.70 - 133707 - 1 3664073 - 2.70 - 133707 - X 3664073 - 2.70 - 133707 - 2 3664200 - 1.70 - 193144 - 1 3664200 - 1.70 - 193144 - X 3664200 - 1.70 - 193144 - 2 However the output should be displayed as: 3664066 - 1.50 - 133702 - 1 3664073 - 2.70 - 133707 - X 3664200 - 1.70 - 193144 - 2 Each alternative is being assigned 3 times to a specific odd. Your expert advice would be greatly appreciated again! Thanks again !!
  5. Hi Dj Kat, Any chance you can show me what the code should look like as I am still stuck ? Cheers, Rob.
  6. HI Guys, i am having a little trouble parsing the below xml feed. <game id="3664066" date="20090325" time="1700"> − <description> <category id="SOCMENEURESPSEGB1" order="7200">Spa. Segunda B1</category> Celta B - Valladolid B </description> <type id="0"/> − <alternatives> <alternative odds="1.50" team="133702">1</alternative> <alternative odds="3.50" team="133702">X</alternative> <alternative odds="5.95" team="193111">2</alternative> </alternatives> </game> I need to display the above xml feed in the following format: game id , alternative odds, alternative team , alternative type[1] game id , alternative odds, alternative team , alternative type[x] game id , alternative odds, alternative team , alternative type[2] I am currently using the below php code. $xml = new SimpleXMLElement($source,null,true); foreach($xml as $game) { $game_id = $game['id']; $odds = $game->alternatives->alternative['odds']; $team = $game->alternatives->alternative['team']; $odds_type = $game->alternatives->alternative; echo "{$game_id} - {$odds} - {$team} - {$odds_type}<br>"; } And that is only displaying the first alternative, in this case [1] and ignoring [X] and [2] I hope that i have made my self clear. :-\ . Any advice would be greatly appreciated. Thanks in advance!!
  7. For anyone who runs into the same problem. <?php //mysql connection $con2 = mysql_connect("localhost","username","lpasswd"); if (!$con2) { die('Could not connect: ' . mysql_error()); } $selectdb = mysql_select_db("odds", $con2); if (!$selectdb) { die('Database not used: ; ' . mysql_error()); } //simplexml load xml file $library = simplexml_load_file('http://abcd1234.com/library.xml'); //loop through parsed xmlfeed and print output foreach ($library->shelf as $shelf) { printf($shelf['id']); $current_shelf = $shelf['id']; foreach ($shelf->book as $book) { printf("Title: %s\n", $book->title); printf("Author: %s\n", $book->author); //insert into databse mysql_query("INSERT INTO books (shelf_id, title, author)VALUES (\"$current_shelf\",\"$book->title\", \"$book->author\")") or die(mysql_error()); //show updated records printf ("Records inserted: %d\n", mysql_affected_rows()); } } //close connection mysql_close($con2); ?>
  8. Hi Guys, I have been up all night but still have not managed to find a solution for this. So your help will be greatly appreciated I want parse the below xml file using simplexml and add the contents to a mysql database. XML Feed <?xml version="1.0"?> <library> <shelf id="fiction"> <book> <title>Of Mice and Men</title> <author>John Steinbeck</author> </book> <book> <title>Harry Potter and the Philosopher's Stone</title> <author>J.K. Rowling</author> </book> </shelf> <shelf id="SCIFI"> <book> <title>XFILES</title> <author>Robert Brown</author> </book> <book> <title>When dogs came to earth</title> <author>Albert White</author> </book> </shelf> </library> I created the following table create table books (book_id int primary key auto_increment, shelf_id varchar(40), title varchar(100), author varchar(100)); Now the problem stars when I use the below php script and try to add the shelf_id , title and author to the databse (im not sure how to do this ) <?php $con1 = mysql_connect("localhost","user","pass"); if (!$con1) { die('Could not connect: ' . mysql_error()); } mysql_select_db("library", $con1); $library = simplexml_load_file('http://XXXXXXXXXX/library.xml'); mysql_query("INSERT INTO books (shelf_id, title, author) VALUES (XXXX,XXXX,XXXXX)") or die(mysql_error()); } mysql_close($con1); ?> Once again i would realy appreciate some assistance here ! Thanks in advance!!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.