Link to home
Start Free TrialLog in
Avatar of Tom Powers
Tom Powers

asked on

Transfer xml data from one table to another table

I have a NFL gamelog I need to code it for a live version but this will be simulated game,
I have one table for the current play then I have a table I use as the gamelog it gathers plays that occur after current play. With The game log I need scrollbars on the right the code and there is in the code. I need data to flow current table then gamelog table and gamelog stores it but doesn't suck up any duplicates.


http://www.powerzsoftware.com/tsn/Gameseq.html

Source Code

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
.title {
	color: #FFF;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 25px;
    font-weight: bold;
}
.textborder {
	border: medium solid #063;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #000;
	text-align: center;
	vertical-align: middle;
}
.tablebord {
	border: medium solid #060;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
   
        <script type="text/javascript">
            var xmlPath = '.' //'/xml/nfl/scores/real';
            var xmlGameID = '4295'; 
            var counterXml = 0;
            var counterSeq = 1; // 1 = start from the beginning (full match replay), use -1 to start at end (then it will also search for start of last drive automatically now)
            var counterInit = false;
            var xmlGameDrive = 4295;
			var msg;
			var PossID,PlaySeq,PossIDbak,Quarter,TimeLeft,ResultingToGo,ResultingDown,TotalYards,PlayType,ScoringPlay,FinalYard;
			function gettext() {
              
                $.ajax({
                    type: "GET",
                    url: xmlPath + "/" + xmlGameDrive + '_' + "DRIVE" + ".xml",
                    dataType: "xml",
                    success: function (data, textStatus, jqXHR) {

                        var d = $(data);
var Play = d.find('Play');
	   PossID = Play.attr('PossID');
                       
                        if (counterSeq == -1) { // init to last Seq in file
                            lastSeq = 1 * d.find('Play').last().attr('Seq');
                            if (lastSeq > counterSeq) {
                                counterSeq = lastSeq; // skip to end
                            }
                            counterInit = true;
                        }

                        msg = "";
                        
                        var PlaySeq = d.find('Play[Seq="' + counterSeq + '"]');
                        if (PlaySeq.length > 0) {
                            PossIDbak = PossID;
                            PossID = PlaySeq.attr('PossID');

                            // find start of current DRIVE based on PossID
                            if (counterInit) {
                                counterInit = false;
                                var playNodes = d.find('Play');
                                for (var intCounter = playNodes.length - 1; intCounter >= 0; intCounter--) {
                                    var tempSeq = $(playNodes[intCounter]).attr('Seq');
                                    if (tempSeq < counterSeq) {
                                        if ($(playNodes[intCounter]).attr('PossID') == PossID) {
                                            counterSeq = tempSeq;
                                        } else {
                                            break;
                                        }
                                    }
                                }
                            }

	   $('#imgcur').attr('src', 'http://powerzsoftware.com/tsn/nfl/PS/' + PossID + '.png');
                            msg = PlaySeq.find('narrative').attr('text');
                            $('#txtGametext').html(msg);
                           
                            Quarter = PlaySeq.attr('Quarter');
							$('#txtQ').html(Quarter);
                            TimeLeft = (PlaySeq.attr('TimeLeft'))
							$('#txttime').html(TimeLeft);
                            PlayType = (PlaySeq.attr('PlayType'));
							$('#txtplaytype').html(PlayType);
                            TotalYards = (PlaySeq.attr('TotalYards'));
							$('#txtYdsgain').html(TotalYards);
                            
                            FinalYard = (PlaySeq.attr('FinalYard'));
							$('#txtballon').html(FinalYard);
                            ResultingDown = (PlaySeq.attr('ResultingDown'));
							$('#txtdown').html(ResultingDown);
                           
                            ResultingToGo = (PlaySeq.attr('ResultingToGo'));
                            $('#txtyards').html(ResultingToGo);
                      $('#imgcur1').attr('src', 'http://powerzsoftware.com/tsn/nfl/PS/' + PossID + '.png');	       
               prevplays(d);

                           counterSeq++;
                        } else {
                            lastSeq = 1 * d.find('Play').last().attr('Seq');
                            if (lastSeq > counterSeq) {
                                counterSeq++; // skip missing Seq
                            }
                        }


                    },
                    error: function () {
                        //counterXml = -1;
                    }
                });
            }
			
			
			function prevplays(d) {
    d.find('Play').each(function(i, Play){
        var playNode = $(Play);
        var tr = $('<tr/>');
		var str = 	
	'<td></td><td>' + playNode.attr('Quarter') + '</td><td>'; + playNode.attr('TimeLeft') + '</td><td>'; + playNode.attr('PlayType') + '</td><td>'; + playNode.attr('TotalYards') + '</td><td>'; + playNode.attr('FinalYard') + '</td><td>' + playNode.attr('ResultingDown') + '</td><td>'; + playNode.attr('ResultingToGo') + '</td><br /><td>' + playNode.find('narrative').attr('text') +'</td>';
        tr.append(str);
        $('#scrolltable').append(tr);
    });
}
          
			</script>
</head>

<body>
<table width="750" height="113" border="0" class="textborder">
  <tr>
    <td colspan="8" bgcolor="#006633"><div align="center" class="title">Current Play</div></td>
  </tr>
  <tr>
    <td width="99" bgcolor="#E5E5E5"><div align="center"><strong>Team</strong></div></td>
    <td width="85" bgcolor="#E5E5E5"><div align="center"><strong>Quarter</strong></div></td>
    <td width="91" bgcolor="#E5E5E5"><div align="center"><strong>TimeLeft</strong></div></td>
    <td width="110" bgcolor="#E5E5E5"><div align="center"><strong>Playtype</strong></div></td>
    <td width="99" bgcolor="#E5E5E5"><div align="center"><strong>Yards Gained</strong></div></td>
    <td width="86" bgcolor="#E5E5E5"><div align="center"><strong>Ball on the</strong></div></td>
    <td width="57" bgcolor="#E5E5E5"><div align="center"><strong>Down</strong></div></td>
    <td width="89" bgcolor="#E5E5E5"><div align="center"><strong>Yards to go</strong></div></td>
  </tr>
  <tr>
    <td height="56" bgcolor="#FFFF99"><div align="center"><img src="http://powerzsoftware.com/tsn/nfl/PS/082.png" name="imgcur" width="60" height="45" id="imgcur"></div></td>
    <td bgcolor="#FFFF99"><div align="center" id="txtQ"></div></td>
    <td bgcolor="#FFFF99"><div align="center" id="txttime"></div></td>
    <td bgcolor="#FFFF99"><div align="center" id="txtplaytype"></div></td>
    <td bgcolor="#FFFF99"><div align="center" id="txtYdsgain"></div></td>
    <td bgcolor="#FFFF99"><div align="center" id="txtballon"></div></td>
    <td bgcolor="#FFFF99"><div align="center" id="txtdown"></div></td>
    <td bgcolor="#FFFF99"><div align="center" id="txtyards"></div></td>
  </tr>
</table>
<table width="750" height="55" border="0" class="textborder">
  <tr>
    <td bgcolor="#FFFF66"><p align="center" id="txtGametext">&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Football Field with drawn lines will go here!</p>
<table width="750" border="0">
  <tr>
    <td bgcolor="#006633"><div align="center" class="title"> Play by Play Game Log</div></td>
  </tr>
</table>
<table width="750" border="0">
  <tr bgcolor="#E6E6E6" class="textborder">
    <td width="104"><strong>Team</strong></td>
    <td width="82"><strong>Quarter</strong></td>
    <td width="89"><strong>TimeLeft</strong></td>
    <td width="108"><strong>Playtype</strong></td>
    <td width="96"><strong>Yards Gained</strong></td>
    <td width="83"><strong>Ball on the</strong></td>
    <td width="61"><strong>Down</strong></td>
    <td width="93"><strong>Yards to go</strong></td>
  </tr>
</table>
<div style='height: 400px; overflow-y: scroll;'>
<table width="750" border="0" class="tablebord" id="scrolltable">
  <tr bgcolor="#FFFF99">
    <td width="106"><div align="center">
      <p><img src="PS/081.png" name="imgcur1" width="85" height="65" id="imgcur1"></p>
    </div></td>
    <td width="78"><div align="center" id="txtQQ"></div></td>
    <td width="88"><div align="center" id="txttime1"></div></td>
    <td width="109"><div align="center" id="txtplaytype"></div></td>
    <td width="96"><div align="center" id="txttotalyds"></div></td>
    <td width="83"><div align="center" id="txtballon1"></div></td>
    <td width="59"><div align="center" id="txtdown1"></div></td>
    <td width="89"><div align="center" id="txtyards1"></div></td>
  </tr>
  <tr>
    <td colspan="8" bgcolor="#FFFF66"><div align="center">
      <p id="txtgameplay">&nbsp;</p>
      <p>&nbsp;</p>
    </div></td>
  </tr>
</table>
<table width="750" border="0">
  <tr>
    <td><div align="center">
      <input type="submit" name="btnScore" id="btnScore" value="Scoring Plays">
      <input type="submit" name="btnCompletes" id="btnCompletes" value="Completed Passes">
      <input type="submit" name="btnCompletes2" id="btnCompletes2" value="Sacks">
      <input type="submit" name="btnCompletes3" id="btnCompletes3" value="Interceptions">
    </div></td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; </p>
<script>
var myVar=setInterval(myTimer,1000);

function myTimer()
{
	gettext();
}
  </script>
</body>
</html>

Open in new window

Attached is zip folder with xml and html cause ee changes name of xml file
NFLGAMEPLAY.zip
Avatar of KNVB HK
KNVB HK
Flag of Hong Kong image

What do you mean duplicate? whole table? or only the previous row?
@powerztom - can you explain in detail what you need. Treat me as if I know nothing about NFL (I don't!!).

It looks like every second you will read an XML file that contains a list of 'Plays'. I guess this list grows as the game go on, and each time you read the XML file, you want to add the new plays to your HTML.

I don't quite understand the bit about the current play and game log. If you read the XML and there's 4 new 'Plays', what would you do with them.

I need this in layman's terms - not football terms! Football to me is played with a round ball, over two 45minutes halves :)
Avatar of Tom Powers
Tom Powers

ASKER

OK,

THERE IS ONE XML FILE HOWEVER that file gets updated each time one football play happens. In American Football one play occurs then stops then players lineup and another play happens. Well each play that xml file gets updated. the xml file that gets updated that information gets displayed in a current html table current is just a name I call it, and below is another table and that's where I'm having a issue that's where the previous plays get loaded into. That 2nd table will get large so I need scrollbars to stick directly to the table. and not inches away like I have it. In the xml file each play has a seq number when the game is over you have one xml file that has a seq number for everyplay in the game. About American football. One team gets the ball the ball is marked down at a spot on the field 10 yards down the field is another marker called first down marker . The team with the ball has 4 chances to get beyond 10 yards to get another set of 4 downs to reach past another 10 yards. You can pass and run to make it into the endzone where you score 6 points. That's a little bit about football the game and hopefully what I'm looking to down on this page. But this link the Play by Play Game Log is where I need previous plays to be dropped in. http://www.powerzsoftware.com/tsn/Gameseq.html

Look at zip file attached above and see html code and xml file structure.
According to 4295_DRIVE.xml it contains several "records" for each quarter.
The game log just display what data in  4295_DRIVE.xml,so it is duplicate.

Would you tell me what do you want to show in game log table?
4295_DRIVE.xml shows seq drives for game stats 4295.xml is for the same game just player stats.
Hey powerztom,

Had some time and fancied the challenge so I've looked through your code and re-factored it. Couple of bits in your code that I didn't understand, so I've skipped them, but this code seems to do what you need.

The only thing I wasn't sure about was how you wanted the previous plays adding. For example, if when you load up the page, there are 10 plays already in the file, I've coded it so that the last play is added to the Current Play table and the other 9 are added to the Game Log table. It's also coded so that any new plays are added to the Game Log table in one go, so if there were 5 plays between your script running, it would add them all to the game log.

Have a play around with what I've posted (next comment) and see if it's close to what you need. I've commented the code so hopefully you'll follow what I've done.

Any questions, just ask.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good job Chris It worked I'm impressed Now I get to look at someone else's code (Being You) and learn different styles. That is what makes this site great. I learn off my buddy Robert S. Then you come along and accept a maybe difficult challenge and a working solution is created and this just helps me and it may be a pain in the ass but it helps you or challenges you.But you did a great job chris I'm extremely thankful.
Chris the main reason why I wanted a gamelog table is to have buttons created or maybe a dropdown of playtypes and filter through them in the game log One example would be INTERCEPTION or COMPLETE TD or SACK Believe me to lazy couch potato football watching fat man that would be huge. I'm going to put in a ticket hopefully you are up for it cause you are familiar and did a great job on this one.
Glad I could help - enjoyed the challenge :)

If you add another related question, post a comment in here with a link to the new question and I'll be notified automatically. I can then take a look.
Chris,

here you go and Don't worry about current log I'm gonna use that at the top of page the game log is going to be several components below current play. Read the description brother thanks again.https://www.experts-exchange.com/questions/28288228/Filter-and-display-a-particular-value-and-display-it-in-the-game-log-table.html
Chris thanks for your work I have a complex scenario. It's like what you did already let me explain In basketball there are similar values to make a game log the only thing is when they or people before me made the basketball app they just had values like gametext player pic playtype time but they never saved it to the next xml file The updated xml file has new values but there is no game seq number so can a virtual table be created and saved then we can do dropdown list. That list would be big cause the NBA ACTION MOVES QUICK. Thanks for setTimeout(getData,2000); I was getting javascript message box unresponsive script using SetInterval 1000 so I changed it to setTimeout(getData 2000) and the message has gone away. Let me know about virtual table and save data as xml for basketball. Thanks Chris
Without some way of identifying the order of plays, such as a Seq number, it's probably going to be trickier. Not sure what you mean by a virtual table.
Chris I put in a ticket similar to football this time it's hockey but I just need a dropdown to control the data that is in the table. You did such a kick ass job last time that I was hoping to get your help.
Can't see a new question - post a link to it here and I'll automatically get notified, and then I'll have a look.