You are here:  » Formating the Parsed XML Data


Formating the Parsed XML Data

Submitted by JohnnyBoy on Tue, 2007-03-20 19:42 in

This link below is the PHP code for parsing the XML data feed which works great and shows the results for all the data needed... This works great!

LINK - http://www.sportsrumble.com/xml/temp.php

This link shows the results from the coding above...

LINK - http://www.sportsrumble.com/xml/

This link below shows an example of how I need to get the results to actually show.

LINK - http://www.sportsrumble.com/xml/odds_example.jpg

I know I have to nest the Table tag outside the parser to get this result but when I use the code below the example link I get negative results. Please help me to make sense of this.

<?php
require("MagicParser.php");
    print 
"<table border='1'>";
  function 
myRecordHandler($record)
  {
    print 
"<tr>";
    
// create the game / books entry in this row
           
print "<th>Date & Time</th>";
        print 
"<th>#</th>";
        print 
"<th>Teams</th>";
        print 
"<th>Book1 Image</th>";
        print 
"<th>Book2 Image</th>";
        print 
"<th>Book3 Image</th>";
        print 
"<th>Book4 Image</th>";
        print 
"<th>Book5 Image</th>";
        print 
"</tr>";
  }
  
// parse the file to populate the rows
  
MagicParser_parse("http://www.pointspread.com/liveodds/xml/xml_general_nba.xml","myRecordHandler","xml|ODDS/GAME/");
  
// finally close the table
  
print "</table>";
?>

Submitted by support on Wed, 2007-03-21 10:59

Hi,

You really need to take a different approach here in order to display the data in a tabular way as per your example.

What you need to do is to create your title row outside of the parsing loop, and then within the loop you create the row for each game.

Also, instead of displaying the books directly, you need to load the books into an array of books (indexed by book name), and then pick out the ones you want to display individually.

Here's an example i've just put together to demonstrate this:

http://www.magicparser.com/examples/nba2.php

Here's the source code:

<?php
  
require("MagicParser.php");
  print 
"<style type='text/css'>table {font-size: small; font-family: arial;}</style>";
  print 
"<table border='1'>";
  print 
"<tr>";
  print 
"<th>Date &amp; Time</th>";
  print 
"<th>#</th>";
  print 
"<th>Teams</th>";
  print 
"<th>beted2 Image</th>";
  print 
"<th>betjamaica2 Image</th>";
  print 
"<th>sportsbook Image</th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
  {
    print 
"<tr>";
    
// first display the game information columns
    
print "<td valign='top'>".$record["GAME-DATE"]."<br />".$record["GAME-TIME"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AWAYML"] = $record["BOOK".$postfix."-AWAYML"];
      
$books[$bookName]["HOMEML"] = $record["BOOK".$postfix."-HOMEML"];
      
$books[$bookName]["AWAYSPREAD"] = $record["BOOK".$postfix."-AWAYSPREAD"];
      
$books[$bookName]["AWAYLINE"] = $record["BOOK".$postfix."-AWAYLINE"];
      
$books[$bookName]["HOMESPREAD"] = $record["BOOK".$postfix."-HOMESPREAD"];
      
$books[$bookName]["HOMELINE"] = $record["BOOK".$postfix."-HOMELINE"];
      
$books[$bookName]["TOTAL"] = $record["BOOK".$postfix."-TOTAL"];
      
$books[$bookName]["OVERLINE"] = $record["BOOK".$postfix."-OVERLINE"];
      
$books[$bookName]["UNDERLINE"] = $record["BOOK".$postfix."-UNDERLINE"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("beted2","betjamaica2","sportsbook");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
    {
       print 
"<td>";
       print 
$books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print 
"<br />";
       print 
$books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print 
"<br />";
       print 
$books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print 
"</td>";
    }
    print 
"</tr>";
  }
  
MagicParser_parse("nba.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

You'll notice that in this version we aren't using the "bookname"=>1 style because all we want this time is the name of the books you want to display. The order of the books in the array on this line...

    $useBooks = array("beted2","betjamaica2","sportsbook");

...must match the order of the books (or rather their images) in the title row of your table. I appreciate that there are some quite advanced PHP techniques being used in this demo, but hopefully you are able to use it as a starting point.

Cheers,
David.

Submitted by JohnnyBoy on Thu, 2007-03-22 18:42

Two questions now... should be easy ones... Again I appreciate all your help David... Actually lets make it three questions...

1. Besides Magic Parser is there any other prodcut/services you offer because I would love to check them out. This has been one of the best products/support I have ever recieved and will recomend this site to everyone in the industry. In fact on one of my sites I will put a link to here if that is ok with you?

2. How do I convert the time from 24 hour clock to regular 12 hour? for example if it says 20:04 for time I would like to display 8:04... Its just a matter of converting the format... I know the code would be "date('g:i:s A')", but I am having problems converting it...

3. When some fields in the table are empty and have no Data it still will result with "ov" in the field like it should. but what is the way to show an "N/A" in that cell instead for fields that contain empty data...

Thank you

Submitted by JohnnyBoy on Thu, 2007-03-22 18:46

Also instead of the Date showing (03/22/2007) it would only show (3/22)... I know if I get the the answer for the time then the same would follow for the date in regards to formatting it... Again sorry to be a pain and thank you for all your help...

Submitted by JohnnyBoy on Fri, 2007-03-23 06:21

Also now on top of the 50 questions I have asked.. :) I want to make every other row have a background color of lets say '#E9E9E9'. I know I have to do this inside the parse because the data is a variable in relation to how many row sets it outputs... so, the number of every other row being that background color will be unknown. Am I on the right track? If so how can I accomplish this?

Submitted by support on Fri, 2007-03-23 13:04

Hi,

1/
My only other product is Price Tapestry, which is a Price Comparison Script and uses Magic Parser. If you are interested in Price Tapestry send me an email and I will send you an upgrade link because you have already bought Magic Parser...
http://www.PriceTapestry.com/

2/
Try this to convert the time:
$date = $record["GAME-DATE"]." ".$record["GAME-TIME"];
$date = strtotime($date);
$date = date("g:i:s A",$date);

3/
To check for empty data, simply test the value before printing - for example:

    if ($books[$bookName]["HOMESPREAD"])
    {
       print "<td>";
       print $books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print "<br />";
       print $books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print "<br />";
       print $books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print "</td>";
    }
    else
    {
      print "<td>N/A</td>";
    }

4/
To reformat the date - use the same code above but use a different format in the date() function...

5/
The trick here is to use the mod "%" operator, and set a global counter and then change the background color every odd row. At the moment at the top of the record handler function you have;

print "<tr>";

Try this:

global $counter;
if ($counter++ % 2)
{
  print "<tr>";
}
else
{
  print "<tr bgcolor='#E9E9E9'>";
}

Hope this helps!
Cheers,
David.

Submitted by JohnnyBoy on Sat, 2007-03-24 14:07

Thanks David... Again you are the shite!!!!!! ;) I got the date and time converted with no problem... I know its easy for a guru like you but for me its a big step in the right direction... :) This whole project has been an enjoyable learning experience for me and I partly have you to thanks for that...

Only problem is the background color on the row and the Empty fields... Here is my code the way I put it together... Let me know what I am doing wrong... Thanks bru

<?php
    
require("MagicParser.php");
  print 
'<link href="http://www.sportsrumble.com/xml/styles.css" rel="stylesheet" type="text/css">';
    print 
"<table border='1' align='center' cellspacing=\"2\" cellpadding=\"2\">";
  print 
"<tr>";
  print 
"<th>Date &amp; Time</th>";
  print 
"<th>Teams</th>";
  print 
"<th>#</th>";
  print 
"<th><img src=\"images/bodog2.gif\"></th>";
  print 
"<th><img src=\"images/VIPsports.jpg\"></th>";
  print 
"<th><img src=\"images/sportinteraction2_rollover.gif\"></th>";
  print 
"<th><img src=\"images/sportsbook_com.jpg\"></th>";
  print 
"<th><img src=\"images/betgameday.jpg\"></th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
  
/* Old Row creation w/o background color on every other one
      {
    print "<tr>";
    */
    //Create Row with background color - NOT WORKING
    
global $counter;
    if (
$counter++ % 2)
    {
      print 
"<tr>";
    }
    else
    {
      print 
"<tr bgcolor='#E9E9E9'>";
    }
    
//Convert the time
    
$time $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$time strtotime($time);
    
$time date("g:i A",$time);
    
//Convert the Date
    
$date $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$date strtotime($date);
    
$date date("d-M",$date);
    
// first display the game information columns
    
print "<td valign='top'>".$time."<br />".$date."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AWAYML"] = $record["BOOK".$postfix."-AWAYML"];
      
$books[$bookName]["HOMEML"] = $record["BOOK".$postfix."-HOMEML"];
      
$books[$bookName]["AWAYSPREAD"] = $record["BOOK".$postfix."-AWAYSPREAD"];
      
$books[$bookName]["AWAYLINE"] = $record["BOOK".$postfix."-AWAYLINE"];
      
$books[$bookName]["HOMESPREAD"] = $record["BOOK".$postfix."-HOMESPREAD"];
      
$books[$bookName]["HOMELINE"] = $record["BOOK".$postfix."-HOMELINE"];
      
$books[$bookName]["TOTAL"] = $record["BOOK".$postfix."-TOTAL"];
      
$books[$bookName]["OVERLINE"] = $record["BOOK".$postfix."-OVERLINE"];
      
$books[$bookName]["UNDERLINE"] = $record["BOOK".$postfix."-UNDERLINE"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("bodog2","vipsports2","sportinteraction2","sportsbook","betgameday2");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
/* Old return of data without Blank fields being returned as N/A
   {
       print "<td>";
       print $books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print "<br />";
       print $books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print "<br />";
       print $books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print "</td>";
    }
    print "</tr>";
  }
  */
  // Return of Empty fields as N/A - NOT WORKING
      
if ($books[$bookName]["HOMESPREAD"])
    {
       print 
"<td>";
       print 
$books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print 
"<br />";
       print 
$books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print 
"<br />";
       print 
$books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print 
"</td>";
    }
    else
    {
      print 
"<td>N/A</td>";
    }*/
  
MagicParser_parse("nba.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

Submitted by JohnnyBoy on Sat, 2007-03-24 15:20

Actually I got the background color to show a result now and realized I had to put global variable up on the top before the magic parser function. but my only issue is that the background gets placed on every row instead of every other one... Hmmmm? What do you think I should do?

<?php
  
global $counter;
  require(
"MagicParser.php");
  print 
'<link href="http://www.sportsrumble.com/xml/styles.css" rel="stylesheet" type="text/css">';
  print 
"<table border='1' align='center' cellspacing=\"2\" cellpadding=\"2\">";
  print 
"<tr>";
  print 
"<th>Date &amp; Time</th>";
  print 
"<th>Teams</th>";
  print 
"<th>#</th>";
  print 
"<th><img src=\"images/bodog2.gif\"></th>";
  print 
"<th><img src=\"images/VIPsports.jpg\"></th>";
  print 
"<th><img src=\"images/sportinteraction2_rollover.gif\"></th>";
  print 
"<th><img src=\"images/sportsbook_com.jpg\"></th>";
  print 
"<th><img src=\"images/betgameday.jpg\"></th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
      {
       if (
$counter++ % 2)
    {
      print 
"<tr>";
    }
    else
    {
      print 
"<tr bgcolor='#E9E9E9'>";
    }
    
//Convert the time
    
$time $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$time strtotime($time);
    
$time date("g:i A",$time);
    
//Convert the Date
    
$date $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$date strtotime($date);
    
$date date("d-M",$date);
    
// first display the game information columns
    
print "<td valign='top'>".$time."<br />".$date."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AWAYML"] = $record["BOOK".$postfix."-AWAYML"];
      
$books[$bookName]["HOMEML"] = $record["BOOK".$postfix."-HOMEML"];
      
$books[$bookName]["AWAYSPREAD"] = $record["BOOK".$postfix."-AWAYSPREAD"];
      
$books[$bookName]["AWAYLINE"] = $record["BOOK".$postfix."-AWAYLINE"];
      
$books[$bookName]["HOMESPREAD"] = $record["BOOK".$postfix."-HOMESPREAD"];
      
$books[$bookName]["HOMELINE"] = $record["BOOK".$postfix."-HOMELINE"];
      
$books[$bookName]["TOTAL"] = $record["BOOK".$postfix."-TOTAL"];
      
$books[$bookName]["OVERLINE"] = $record["BOOK".$postfix."-OVERLINE"];
      
$books[$bookName]["UNDERLINE"] = $record["BOOK".$postfix."-UNDERLINE"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("bodog2","vipsports2","sportinteraction2","sportsbook","betgameday2");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
// Old return of data without Blank fields being returned as N/A
   
{
       print 
"<td>";
       print 
$books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print 
"<br />";
       print 
$books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print 
"<br />";
       print 
$books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print 
"</td>";
    }
    print 
"</tr>";
  }
/*
// Return of Empty fields as N/A - NOT WORKING
      if ($books[$bookName]["HOMESPREAD"])
    {
       print "<td>";
       print $books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print "<br />";
       print $books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print "<br />";
       print $books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print "</td>";
    }
    else
    {
      print "<td>N/A</td>";
    }
    //End of Return field with N/A
    */
  
MagicParser_parse("nba.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

Submitted by support on Sat, 2007-03-24 20:01

Hi,

The global declaration is in the wrong place - that's all it is. It needs to go immediately inside your record handler function, so you have the following:

function myRecordHandler($record)
      {
       global $counter;
       if ($counter++ % 2)

That should be all it is!

Cheers,
David.

Submitted by JohnnyBoy on Sat, 2007-03-24 21:13

Yep, got that to work... Thanks... The only other issue is the Empty fields not showing a 'N/A'... Also if I want to show only the data for todays date then would I need to create a variable that would equal todays date and then an if statement that would only display the data if the date is equal to today's date?

Here is my code for that and it shows no reults at all now when I check for empty fields to insert the 'N/A' into...

<?php
  
require("MagicParser.php");
  print 
'<link href="http://www.sportsrumble.com/xml/styles.css" rel="stylesheet" type="text/css">';
  print 
"<table border='1' align='center' cellspacing=\"2\" cellpadding=\"2\">";
  print 
"<tr>";
  print 
"<th>Date &amp; Time</th>";
  print 
"<th>Teams</th>";
  print 
"<th>#</th>";
  print 
"<th><img src=\"images/bodog2.gif\"></th>";
  print 
"<th><img src=\"images/VIPsports.jpg\"></th>";
  print 
"<th><img src=\"images/sportinteraction2_rollover.gif\"></th>";
  print 
"<th><img src=\"images/sportsbook_com.jpg\"></th>";
  print 
"<th><img src=\"images/betgameday.jpg\"></th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
       {
    global 
$counter;
       if (
$counter++ % 2)
    {
      print 
"<tr>";
    }
    else
    {
      print 
"<tr bgcolor='#E9E9E9'>";
    }
    
//Convert the time
    
$time $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$time strtotime($time);
    
$time date("g:i A",$time);
    
//Convert the Date
    
$date $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$date strtotime($date);
    
$date date("d-M",$date);
    
// first display the game information columns
    
print "<td valign='top'>".$time."<br />".$date."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AWAYML"] = $record["BOOK".$postfix."-AWAYML"];
      
$books[$bookName]["HOMEML"] = $record["BOOK".$postfix."-HOMEML"];
      
$books[$bookName]["AWAYSPREAD"] = $record["BOOK".$postfix."-AWAYSPREAD"];
      
$books[$bookName]["AWAYLINE"] = $record["BOOK".$postfix."-AWAYLINE"];
      
$books[$bookName]["HOMESPREAD"] = $record["BOOK".$postfix."-HOMESPREAD"];
      
$books[$bookName]["HOMELINE"] = $record["BOOK".$postfix."-HOMELINE"];
      
$books[$bookName]["TOTAL"] = $record["BOOK".$postfix."-TOTAL"];
      
$books[$bookName]["OVERLINE"] = $record["BOOK".$postfix."-OVERLINE"];
      
$books[$bookName]["UNDERLINE"] = $record["BOOK".$postfix."-UNDERLINE"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("bodog2","vipsports2","sportinteraction2","sportsbook","betgameday2");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
// Return of Empty fields as N/A - NOT WORKING
      
if ($books[$bookName]["HOMESPREAD"])
    {
       print 
"<td>";
       print 
$books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print 
"<br />";
       print 
$books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print 
"<br />";
       print 
$books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print 
"</td>";
    }
    else
    {
      print 
"<td>N/A</td>";
    }
    
//End of Return field with N/A
  
MagicParser_parse("http://www.pointspread.com/liveodds/xml/xml_general_nba.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

Submitted by support on Sun, 2007-03-25 11:24

Hi,

There was a slight formatting error in the above code, but was probably just down to the cut/paste. I have run the script on my own server, and the reason that some fields are displaying "ov" with no date (when you want N/A in the entire cell) I think is because whilst some of the values area missing the value that was being tested still contained data. I've changed this to test against the TOTAL column, which may be what you want to do - check this carefully though....

I've also included in this version a comparison with today's date, with an IF statement that exits from the record handler if the game is not today. Notice how I have moved the code to start the table row down below this point, because otherwise your alternating shaded rows would go out of sync!

<?php
  
require("MagicParser.php");
  print 
'<link href="http://www.sportsrumble.com/xml/styles.css" rel="stylesheet" type="text/css">';
  print 
"<table border='1' align='center' cellspacing=\"2\" cellpadding=\"2\">";
  print 
"<tr>";
  print 
"<th>Date &amp; Time</th>";
  print 
"<th>Teams</th>";
  print 
"<th>#</th>";
  print 
"<th><img src=\"images/bodog2.gif\"></th>";
  print 
"<th><img src=\"images/VIPsports.jpg\"></th>";
  print 
"<th><img src=\"images/sportinteraction2_rollover.gif\"></th>";
  print 
"<th><img src=\"images/sportsbook_com.jpg\"></th>";
  print 
"<th><img src=\"images/betgameday.jpg\"></th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
  {
    global 
$counter;
    
//Convert the time
    
$time $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$time strtotime($time);
    
$time date("g:i A",$time);
    
//Convert the Date
    
$date $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$date strtotime($date);
    
$date date("d-M",$date);
    
//Get today's date
    
$today date("d-M");
    
//Exit if not today
    
if ($date <> $today) return;
    
//Display the game
    
if ($counter++ % 2)
    {
      print 
"<tr>";
    }
    else
    {
      print 
"<tr bgcolor='#E9E9E9'>";
    }
    
// first display the game information columns
    
print "<td valign='top'>".$time."<br />".$date."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AWAYML"] = $record["BOOK".$postfix."-AWAYML"];
      
$books[$bookName]["HOMEML"] = $record["BOOK".$postfix."-HOMEML"];
      
$books[$bookName]["AWAYSPREAD"] = $record["BOOK".$postfix."-AWAYSPREAD"];
      
$books[$bookName]["AWAYLINE"] = $record["BOOK".$postfix."-AWAYLINE"];
      
$books[$bookName]["HOMESPREAD"] = $record["BOOK".$postfix."-HOMESPREAD"];
      
$books[$bookName]["HOMELINE"] = $record["BOOK".$postfix."-HOMELINE"];
      
$books[$bookName]["TOTAL"] = $record["BOOK".$postfix."-TOTAL"];
      
$books[$bookName]["OVERLINE"] = $record["BOOK".$postfix."-OVERLINE"];
      
$books[$bookName]["UNDERLINE"] = $record["BOOK".$postfix."-UNDERLINE"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("bodog2","vipsports2","sportinteraction2","sportsbook","betgameday2");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
    
// Return of Empty fields as N/A - NOT WORKING
    
if ($books[$bookName]["TOTAL"])
    {
       print 
"<td>";
       print 
$books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print 
"<br />";
       print 
$books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print 
"<br />";
       print 
$books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print 
"</td>";
    }
    else
    {
      print 
"<td>N/A</td>";
    }
    
//End of Return field with N/A
  
}
  
MagicParser_parse("http://www.pointspread.com/liveodds/xml/xml_general_nba.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

Cheers,
David.

Submitted by JohnnyBoy on Sun, 2007-03-25 16:39

Thank David... Much appreciated... Still the empty fields show the ov instead of the N/A...

Submitted by support on Mon, 2007-03-26 08:09

Hi,

Here's the above code running on this server:

http://www.magicparser.com/examples/nba3.php

Please double check the changes to that area - note that all I changed was to test the "TOTAL" value and display n/a if that is zero...

Cheers,
David.

Submitted by JohnnyBoy on Tue, 2007-03-27 19:54

That seems to be working... Do you have the source code for that?

AGAIN THANK YOU!!!!!!!!!!!!!!!!!

Submitted by JohnnyBoy on Tue, 2007-03-27 22:25

I created a speprate link for the money lines... I did this because I realize that the money lines are not showing up when we are telling it to show that record...

Here is the link:
http://www.sportsrumble.com/odds/moneyline_NBA.php

Here is the code:

<?php
  
require("MagicParser.php");
  print 
'<link href="http://www.sportsrumble.com/xml/styles.css" rel="stylesheet" type="text/css">';
  print 
"<table border='1' width=\"550\" align='center' cellspacing=\"0\" cellpadding=\"1\">";
  print 
"<tr>";
  print 
"<th>Date &amp;<BR>Time</th>";
  print 
"<th>Teams</th>";
  print 
"<th>#</th>";
  print 
"<th><img src=\"images/bodog2.gif\"></th>";
  print 
"<th><img src=\"images/VIPsports.jpg\"></th>";
  print 
"<th><img src=\"images/si.jpg\"></th>";
  print 
"<th><img src=\"images/sportsbook_com.jpg\"></th>";
  print 
"<th><img src=\"images/betgameday.jpg\"></th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
  {
    global 
$counter;
    
//Convert the time
    
$time $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$time strtotime($time);
    
$time date("g:i A",$time);
    
//Convert the Date
    
$date $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$date strtotime($date);
    
$date date("d-M",$date);
    
//Get today's date
    
$today date("d-M");
    
//Exit if not today
    
if ($date <> $today) return;
    
//Display the game
    
if ($counter++ % 2)
    {
      print 
"<tr>";
    }
    else
    {
      print 
"<tr bgcolor='#F2FBFF'>";
    }
    
// first display the game information columns
    
print "<td valign='top'>".$time."<br />".$date."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AwayML"] = $record["BOOK".$postfix."-AwayML"];
      
$books[$bookName]["HomeML"] = $record["BOOK".$postfix."-HomeML"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("bodog2","vipsports2","sportinteraction2","sportsbook","betgameday2");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
    
// Return of Empty fields as N/A - NOT WORKING
    
if ($books[$bookName]["TOTAL"])
    {
       print 
"<td>";
       print 
$books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print 
"<br />";
       print 
$books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print 
"<br />";
       print 
$books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       print 
"</td>";
    }
    else
    {
      print 
"<td>N/A</td>";
    }
    
//End of Return field with N/A
  
}
  
MagicParser_parse("http://www.pointspread.com/liveodds/xml/xml_general_nba.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

Submitted by support on Wed, 2007-03-28 08:37

Hi,

The critical line here is:

if ($books[$bookName]["TOTAL"])

This is where the decision is made to either show the record or display "n/a", and in this case is based entirely on whether there is a TOTAL value in that book. You can use any of the values in the book sub-record here, for example to use HOMESPREAD as the test you would change it to:

if ($books[$bookName]["HOMESPREAD"])

Alternatively, you might need to add a second test to decide whether to display the "ov" line. This would be done in exactly the same way, for example:

    // Return of Empty fields as N/A - NOT WORKING
    if ($books[$bookName]["HOMESPREAD"])
    {
       print "<td>";
       print $books[$bookName]["HOMESPREAD"].$books[$bookName]["HOMELINE"];
       print "<br />";
       print $books[$bookName]["AWAYSPREAD"].$books[$bookName]["AWAYLINE"];
       print "<br />";
       if ($books[$bookName]["TOTAL"])
       {
         print $books[$bookName]["TOTAL"]." ov".$books[$bookName]["OVERLINE"];
       }
       print "</td>";
    }

Hope this helps!
Cheers,
David.

Submitted by JohnnyBoy on Fri, 2007-04-06 09:21

Ok I tried this a few times and I think I am getting to an unmanagable state.. :) HEre is my code and I have tried different avenues and can not get the moneylines to show up and all I get is N/A for this one...

Page:
http://www.sportsrumble.com/odds/moneyline_MLB.php

Code:

<?php
  
require("MagicParser.php");
  print 
'<link href="http://www.sportsrumble.com/xml/styles.css" rel="stylesheet" type="text/css">';
  print 
"<table border='1' width=\"550\" align='center' cellspacing=\"0\" cellpadding=\"1\">";
  print 
"<tr>";
  print 
"<th>Date &amp;<BR>Time</th>";
  print 
"<th>Teams</th>";
  print 
"<th>#</th>";
  print 
"<th><img src=\"images/bodog2.gif\"></th>";
  print 
"<th><img src=\"images/VIPsports.jpg\"></th>";
  print 
"<th><img src=\"images/si.jpg\"></th>";
  print 
"<th><img src=\"images/sportsbook_com.jpg\"></th>";
  print 
"<th><img src=\"images/betgameday.jpg\"></th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
  {
    global 
$counter;
    
//Convert the time
    
$time $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$time strtotime($time);
    
$time date("g:i A",$time);
    
//Convert the Date
    
$date $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$date strtotime($date);
    
$date date("d-M",$date);
    
//Get today's date
    
$today date("d-M");
    
//Exit if not today
    //if ($date <> $today) return;
    //Display the game
    
if ($counter++ % 2)
    {
      print 
"<tr>";
    }
    else
    {
      print 
"<tr bgcolor='#F2FBFF'>";
    }
    
// first display the game information columns
    
print "<td valign='top'>".$time."<br />".$date."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AwayML"] = $record["BOOK".$postfix."-AwayML"];
      
$books[$bookName]["HomeML"] = $record["BOOK".$postfix."-HomeML"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("bodog2","vipsports2","sportinteraction2","sportsbook","betgameday2");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
    
// Return of Empty fields as N/A
    
if ($books[$bookName]["HOMESPREAD"])
    {
       print 
"<td>";
       print 
$books[$bookName]["AwayML"].$books[$bookName]["HomeML"];
        }
    else
    {
      print 
"<td>N/A</td>";
    }
    
//End of Return field with N/A
  
}
  
MagicParser_parse("http://www.pointspread.com/liveodds/xml/xml_general_mlb.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

Submitted by support on Fri, 2007-04-06 09:26

Hi,

In the code you posted; I noticed that you were testing against the HOMESPREAD value to decide whether or not to display the moneyline. As it stands, this wouldn't work because you have not extracted the HOMESPREAD value in the code above where the decision is made.

I've modified your code to test the AwayML value, which you are capturing - so if this values exists then it should be displayed otherwise you will get n/a...

<?php
  
require("MagicParser.php");
  print 
'<link href="http://www.sportsrumble.com/xml/styles.css" rel="stylesheet" type="text/css">';
  print 
"<table border='1' width=\"550\" align='center' cellspacing=\"0\" cellpadding=\"1\">";
  print 
"<tr>";
  print 
"<th>Date &amp;<BR>Time</th>";
  print 
"<th>Teams</th>";
  print 
"<th>#</th>";
  print 
"<th><img src=\"images/bodog2.gif\"></th>";
  print 
"<th><img src=\"images/VIPsports.jpg\"></th>";
  print 
"<th><img src=\"images/si.jpg\"></th>";
  print 
"<th><img src=\"images/sportsbook_com.jpg\"></th>";
  print 
"<th><img src=\"images/betgameday.jpg\"></th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
  {
    global 
$counter;
    
//Convert the time
    
$time $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$time strtotime($time);
    
$time date("g:i A",$time);
    
//Convert the Date
    
$date $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$date strtotime($date);
    
$date date("d-M",$date);
    
//Get today's date
    
$today date("d-M");
    
//Exit if not today
    //if ($date <> $today) return;
    //Display the game
    
if ($counter++ % 2)
    {
      print 
"<tr>";
    }
    else
    {
      print 
"<tr bgcolor='#F2FBFF'>";
    }
    
// first display the game information columns
    
print "<td valign='top'>".$time."<br />".$date."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AwayML"] = $record["BOOK".$postfix."-AwayML"];
      
$books[$bookName]["HomeML"] = $record["BOOK".$postfix."-HomeML"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("bodog2","vipsports2","sportinteraction2","sportsbook","betgameday2");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
    
// Return of Empty fields as N/A
    
if ($books[$bookName]["AwayML"])
    {
       print 
"<td>";
       print 
$books[$bookName]["AwayML"].$books[$bookName]["HomeML"];
       print 
"</td>";
    }
    else
    {
      print 
"<td>N/A</td>";
    }
    
//End of Return field with N/A
  
}
  
MagicParser_parse("http://www.pointspread.com/liveodds/xml/xml_general_mlb.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

Hope this helps!
Cheers,
David.

Submitted by JohnnyBoy on Fri, 2007-04-06 09:34

The values exist and I changed the value to the away line 'AwayML' and even the home value of 'HomeML', which does have data... for instance The first row and column values should be AwayML="+105" HomeML="-125" for the bodog2 book... but N/A shows up anyways...

Also could this section of the code be causing me errors?

    // now load all books into an array indexed by book name so we can display the ones we want
    $books = array();
    $i = 0;
    while(1) {
      if ($i) $postfix = "@".$i;
      $bookName = $record["BOOK".$postfix."-NAME"];
      if (!$bookName) break;
      $books[$bookName]["AwayML"] = $record["BOOK".$postfix."-AwayML"];
      $books[$bookName]["HomeML"] = $record["BOOK".$postfix."-HomeML"];
      $i++;
    }

Submitted by support on Fri, 2007-04-06 09:42

Hi,

Yes - the problem is in that piece of code - I just ran your script on my server. I hadn't spotted this before; but the values used to access the $record array must all be in upper case:

    // now load all books into an array indexed by book name so we can display the ones we want
    $books = array();
    $i = 0;
    while(1) {
      if ($i) $postfix = "@".$i;
      $bookName = $record["BOOK".$postfix."-NAME"];
      if (!$bookName) break;
      $books[$bookName]["AwayML"] = $record["BOOK".$postfix."-AWAYML"];
      $books[$bookName]["HomeML"] = $record["BOOK".$postfix."-HOMEML"];
      $i++;
    }

Here's a fully working version:

<?php
  
require("MagicParser.php");
  print 
'<link href="http://www.sportsrumble.com/xml/styles.css" rel="stylesheet" type="text/css">';
  print 
"<table border='1' width=\"550\" align='center' cellspacing=\"0\" cellpadding=\"1\">";
  print 
"<tr>";
  print 
"<th>Date &amp;<BR>Time</th>";
  print 
"<th>Teams</th>";
  print 
"<th>#</th>";
  print 
"<th><img src=\"images/bodog2.gif\"></th>";
  print 
"<th><img src=\"images/VIPsports.jpg\"></th>";
  print 
"<th><img src=\"images/si.jpg\"></th>";
  print 
"<th><img src=\"images/sportsbook_com.jpg\"></th>";
  print 
"<th><img src=\"images/betgameday.jpg\"></th>";
  print 
"</tr>";
  function 
myRecordHandler($record)
  {
    global 
$counter;
    
//Convert the time
    
$time $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$time strtotime($time);
    
$time date("g:i A",$time);
    
//Convert the Date
    
$date $record["GAME-DATE"]." ".$record["GAME-TIME"];
    
$date strtotime($date);
    
$date date("d-M",$date);
    
//Get today's date
    
$today date("d-M");
    
//Exit if not today
    //if ($date <> $today) return;
    //Display the game
    
if ($counter++ % 2)
    {
      print 
"<tr>";
    }
    else
    {
      print 
"<tr bgcolor='#F2FBFF'>";
    }
    
// first display the game information columns
    
print "<td valign='top'>".$time."<br />".$date."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMESHORT"]."<br />".$record["GAME-AWAYSHORT"]."</td>";
    print 
"<td valign='top'>".$record["GAME-HOMEROT"]."<br />".$record["GAME-AWAYROT"]."</td>";
    
// now load all books into an array indexed by book name so we can display the ones we want
    
$books = array();
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$bookName $record["BOOK".$postfix."-NAME"];
      if (!
$bookName) break;
      
$books[$bookName]["AwayML"] = $record["BOOK".$postfix."-AWAYML"];
      
$books[$bookName]["HomeML"] = $record["BOOK".$postfix."-HOMEML"];
      
$i++;
    }
    
// create an array of the books we want, matching the title row
    
$useBooks = array("bodog2","vipsports2","sportinteraction2","sportsbook","betgameday2");
    
// now display each book in $useBooks array
    
foreach($useBooks as $bookName)
    
// Return of Empty fields as N/A
    
if ($books[$bookName]["AwayML"])
    {
       print 
"<td>";
       print 
$books[$bookName]["AwayML"].$books[$bookName]["HomeML"];
       print 
"</td>";
    }
    else
    {
      print 
"<td>N/A</td>";
    }
    
//End of Return field with N/A
  
}
  
MagicParser_parse("http://www.pointspread.com/liveodds/xml/xml_general_mlb.xml","myRecordHandler","xml|ODDS/GAME/");
  print 
"</table>";
?>

Hope this helps!
Cheers,
David.

Submitted by JohnnyBoy on Fri, 2007-04-06 09:53

That helped completely... THANK YOU AGAIN... See!!! I am getting better at this!! :) I knew somewhere in there the syntax was doing something wrong but I was worried of getting to a point where the code was to be scratched and needed to be redone... Thanks david...