Forum Moderators: coopster
For example: if I have 10 occurrences of the <team-stat> element
$n = numberofoccurrences;
for (var i=0;i<$n;i++)
{
foreach.........
}
I appreciate the help!
foreach($doc->getElementsByTagName('season')->item(0)->attributes as $attribute){but I am having trouble using
if($attribute->name == "season"){
$season = $attribute->value;
echo $attribute->name . ": " . $attribute->value . "<br>";
}
}
$j = 0;
//get the number of recurrences
foreach($doc->getElementsByTagName('cbk-roster')->item($j)){
$j ++;
}
echo $j;
Parse error: parse error, unexpected ')' in ..... the foreach loop.
Thanks for all the help!
$j = 0;
//get the number of recurrences
$rosters = $doc->getElementsByTagName('cbk-roster');
foreach($rosters as $roster){
$j ++;
}
echo $j;
problem now that I have the number of teams that I have to loop through I have to loop through the number of players.
How can I loop through the player stats inside the school element?
I was thinking of using the item($j) to specify which specific element I want. Maybe adding to the first recurrence check
$j = 0;
$y = 0;
$rosters = $doc->getElementsByTagName('cbk-roster');
foreach($rosters as $roster){
$players= $doc->getElementsByTagName('cbk-player');
foreach($players as $player){
$y++;
}
$j ++;
}
echo $y."<br>";
echo $j."<br>";
//echo count ($doc->cbk-roster[$j]->cbk-player)."<br>";
Parse error: parse error, unexpected '[' in
//get the number of recurrences
$rosters = $doc->getElementsByTagName('cbk-roster');
foreach($rosters as $roster){
echo count ($doc->cbk-roster[$j]->cbk-player)."<br>";
$j ++;
}
$players= $doc->getElementsByTagName('cbk-player');
foreach($players as $player){
$y++;
}
echo $y."<br>";
echo $j."<br>";
Good luck.
Oh, yeah... You're welcome.
//get the number of recurrences
$rosters = $doc->getElementsByTagName('cbk-roster');
foreach($rosters as $roster){
echo count ($doc->cbk-roster[$j]->cbk-player)."<br>";
$j ++;
}
$players= $doc->getElementsByTagName('cbk-player');
foreach($players as $player){
$y++;
}
echo $y."<br>";
echo $j."<br>";
are you running through these and displaying them? or are you just getting counts?
have you looked at what is returned in each part? Does this "$doc->getElementsByTagName('cbk-player');" give you all of the cbk-player elements with no reference to the rosters?
This section of code is just the opening of the parser. I am doing foreach later to pull each individual attributes of the children. And all of the children only have attributes and single tags. I am able to pull each seperate data item but I am not able to loop the schools, and inside that, loop through the players. I am basically trying to count the schools and the number of players per school.
A sample of the xml is below. (edited for space and tos)
<sports-statistics>
<sports-rosters>
<season season="2006"/>
<cbk-rosters>
<cbk-roster>
<team-city city="Fresno State" alias="Fres"/>
<team-name name="Bulldogs"/>
<cbk-player>
<name first-name="First" last-name="Last"/>
</cbk-player>
<cbk-player>
<name first-name="First" last-name="Last"/>
</cbk-player>
<cbk-player>
<name first-name="First" last-name="Last"/>
</cbk-player>
</cbk-roster>
<cbk-roster>
<team-city city="Georgia" alias="UGa"/>
<team-name name="Bulldogs"/>
<cbk-player>
<name first-name="First" last-name="Last"/>
</cbk-player>
<cbk-player>
<name first-name="First" last-name="Last"/>
</cbk-player>
</cbk-rosters>
</sports-rosters>
</sports-statistics>
What I want to do is read the school and first player then write the data for the first player to my database(mysql). then the second, third, etc. till the end of that particular schools player. Then I want to switch to the next school and do it again. I will institute various data verification functions and duplications checks throughout the program. (Those are no problem I have already struggled through them)
My biggest problem is knowing the number of players per school.
I love php5 I just haven't figured it all the way out yet.