Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:52:08+00:00 2026-05-31T15:52:08+00:00

EDIT: Ok I am a bit closer but still need help… http://pastebin.com/9vdhGT2V Disclaimer: This

  • 0

EDIT: Ok I am a bit closer but still need help… http://pastebin.com/9vdhGT2V

Disclaimer: This is my first post after using SO as a resource for quite a while. I am not being lazy I just have exhausted search and I’m close I just need a nudge from some friendly more experienced coders. Thanks in advance!

I am using Simple HTML DOM to run out to Yahoo Sports and grab scores. What I am having trouble with is grouping the two teams that are play together in a table. I know that I will need to count by 2 as it is very predictable I am just having trouble forming it correct.

This is the last piece of working code I have but it does not group by teams playing each other:

http://pastebin.com/0LzrV0Ej

<?php

require('simple_html_dom.php');
$nbaScores = "http://sports.yahoo.com/nba/scoreboard";
$html = file_get_html($nbaScores);

// Find all game info
foreach($html->find('tr.ysptblclbg5') as $scores){
    echo "<table><tr><td>".$scores->find('td',0)->plaintext. "</td>";
    echo "<td>".$scores->find('td',1)->plaintext. "</td>";
    echo "<td>".$scores->find('td',2)->plaintext. "</td>";
    echo "<td>".$scores->find('td',3)->plaintext. "</td>";
    echo "<td>".$scores->find('td',4)->plaintext. "</td>";
    echo "<td>".$scores->find('td',5)->plaintext. "</td>";
    echo "<td>".$scores->find('td',6)->plaintext. "</td>";
    echo "<td>".$scores->find('td',7)->plaintext. "</td></tr></table>";
    }

unset($scores);

?>

Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:52:09+00:00Added an answer on May 31, 2026 at 3:52 pm

    Edit: the code will now reflect the overtime optional TD. I assume $parse->find(“tag[attribute=value]”) returns a table of objects that implement ->plaintext.

    Edit#2: the code will now know which team won a match (using a subtable of $teams).

    Edit#3: based on comments: corrected parenthesis, corrected the team shifting in the table from edit#1

    Never used that parser, so assuming your parsing methods work (and assuming I didn’t get confused in the TD indexes), but anyway here’s the logics:

    $periods=array("QT1","QT2","QT3","QT4","OT","Total");
    $scores=array();
    $teams=array();
    $teamCount=0;
    $matchesCount=0;
    foreach($html->find('tr.ysptblclbg5') as $parse){
        $teams[$matchesCount][$teamCount]['name']=$parse->find('td',1)->plaintext; //TD#2 contains the team name
        //TDs 3 to 6 contain partial scores, TD#7 contains final score or OT score (in which case TD#8 contains final score), they all have the "yspscores" class
        $pscores=$parse->find('td[class=yspscores]');
        for($i=1;$i<count($pscores);$i++) { //we start at 1 instead of 0 as the first TD grabbed is the one where the team name is written, as it also has the yspscores class
            if($i==count($pscores)-1) //if we are at the total score
                $scores[$matchesCount][$teamCount][$periods[count($periods)-1]]=$pscores[$i]->plaintext;
            $scores[$matchesCount][$teamCount][$periods[$i-1]]=$pscores[$i]->plaintext;//$periods[$i-1] as $periods doesn't have a useless offset like $pscores has (part of edit#3)
        }
        $teamCount++; //finished a team and its scores, getting ready to move to the next
        if($teamCount%2==0) { //true if we just parsed the 2nd team of a match
            if($maxMatchScore>$scores[$matchesCount][1][$periods[count($periods)-1]]) //if 1st team won
                $teams[$matchesCount][0]['win']=1;
            else
                $teams[$matchesCount][1]['win']=1;
            $teamCount=0; //then reset the counter as next team will the first team parsed of next match
            $matchesCount++; //and ready to move to next match
        } else {
            $maxMatchScore=$scores[$matchesCount][0][$periods[count($periods)-1]]; //if in the middle of parsing the match, memorize the total score of the first team, to know later who won
        }
    }
    

    There you have 2 tables with teams and scores parsed accordingly to each match. Now you can print them the way you want:

    foreach($teams as $match=>$subarray) { //teams and scores have their indexes coherent, we could have used scores instead, though subarray would have contained the scores instead of the teams (obviously ^^)
        echo "<br /><br />Match #".($match+1).":<br />"; //prints the index of the match in the tables, +1 because "match number zero" is not NBA-friendly...
        foreach($subarray as $id=>$team) { //if we had used scores instead of teams in the global loop, we would have had subarray as id => scoreArray
            if(empty($team['win'])) { //the winner is bold
                $b1="";
                $b2="";
            } else {
                $b1="<b>";
                $b2="</b>";
            }
            echo "Team: ".$b1.$team['name'].$b2.":"; //here team will print with the hyperlink, use a regexp to remove it if needed
            //the following is still valid, but if you need to display a table, you'll have one more TD on matches with OT, which won't look nice
            //foreach($scores[$match][$id] as $scoreType=>$score) { //the table selects one team of one match, and the corresponding subarray gives as keys the type of score (which quarter time, or final score), and as values the score for the paired index.
                //echo $scoreType.":".$score; //prints "qt1:24", or "final:90"
                //echo $scoreType=='final'?'<br />':' / '; //if it is a quarter's score, we separate the next score with a slash, while if it's the final score we <br> (either for the next team or for the next match, as we surely leave this loop, and maybe the previous ine if it was the 2bd team's scores)
            //}
            //version OK for table display or anything else
            foreach($periods as $scoreType) {
                echo $scoreType.":".(empty($scores[$match][$id][$scoreType])?"-":$scores[$match][$id][$scoreType]); //if no OT, we just print "-" where there could have been the OT
                echo $scoreType==$periods[count($periods)-1]?'<br />':' / ';
            }
        }
    }
    

    I didn’t test this code, so there might be some mistypings, but the purpose is for you to have a hint on how to parse the thing in tables, which is easier if you want to focus on your display 😉

    However… I have no legal advice for you, sorry ^^

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Edit: This problem applies only to 32-bit systems. If your computer, your OS and
I really need help getting this query right. I can't share actual table and
I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
EDIT What small things which are too easy to overlook do I need to
EDIT: Ik it is long but does anyone know how to program sockets?? My
I need to do some arithmetic with large hexadecimal numbers below, but when I
I have this application from the market in an apk format, but I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.