Jump to content


Photo

Which variables goes together?


  • Please log in to reply
2 replies to this topic

#1 yeltzin

yeltzin

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 06 April 2013 - 04:16 PM

Hi!

 

In an onlinegame there are teams that has played matches against each other, plenty of teams and they are divided in 16 groups, and i want to know what team's are in the same groups..

 

All the data is stored in mysql and it looks something like this :

 

Games played :

 

Round 1, Team A vs Team B

Round 1, Team C vs Team D

Round 1, Team E vs Team F

Round 1, Team G vs Team H

... and so on

.

Round 2, Team A vs Team E

Round 2, Team C vs Team G

Round 2, Team F vs Team B

Round 2, Team D vs Team H

... and so on

..

Round 3, ..... cont...

..

 

Now i see that team A,B,E, and F plays in the same group, and i want some way to make the script find these combinations for me..

 

Whats the best way to find out these groupings?

 



#2 yeltzin

yeltzin

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 06 April 2013 - 05:25 PM

No need.. found a way.. :)

 

--------------------------

 

$k = 1;

        if ($group[$home] == "" && $group[$away] == "")
        {
            $group[$home] = $k;
            $group[$away] = $k;
            $k = $k + 1;
        }

        if ($group[$home] != "" && $group[$away] != "")
        {
            if ($group[$home] > $group[$away]) $group[$home] = $group[$away];
            if ($group[$home] < $group[$away]) $group[$away] = $group[$home];
        }

        if ($group[$home] != "" && $group[$away] == "")
        {
            $group[$away] = $group[$home];
        }

        if ($group[$home] == "" && $group[$away] != "")
        {
            $group[$home] = $group[$away];
        }



#3 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,135 posts
  • LocationCheshire, UK

Posted 07 April 2013 - 09:31 AM

my 0.02 worth

 

$sql = "SELECT teama,teamb FROM matches
        ORDER BY teama, teamb";
$res = $mysqli->query($sql);
$preva = '';
$groups = array();
while (list($a, $b) = $res->fetch_row()) {
    if ($preva != $a) {
        if ($preva) {
            $inGroup = false;
            foreach ($groups as $teams) {
                if (in_array($a, $teams)) {
                    $inGroup = true;
                    break;
                }
            }
            if (!$inGroup) {
                $groups[$a] = array();
            }
        }
        else $groups[$a] = array();
        $preva = $a;
    }
    if (isset($groups[$a]))
        $groups[$a][] = $b;
}
echo '<pre>',print_r($groups, true),'</pre>';


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com