hello,
I am attempting to make a round robin tournament schedule.
the code works $members,
but when I try to Select player column from database to fill array $players[].
I get Array to string conversion errors
**RoundRobinweb.php**
<?php
/**
*
* Create a round robin of teams or numbers
*
* @param array $players
* @return $array
*
*/
function roundRobin( array $players ){
if (count($players)%2 != 0){
array_push($players,"bye");
}
$away = array_splice($players,(count($players)/2));
$home = $players;
for ($i=0; $i < count($home)+count($away)-1; $i++)
{
for ($j=0; $j<count($home); $j++)
{
$round[$i][$j]["Home"]=$home[$j];
$round[$i][$j]["Away"]=$away[$j];
}
if(count($home)+count($away)-1 > 2)
{
$s = array_splice( $home, 1, 1 );
$slice = array_shift( $s );
array_unshift($away,$slice );
array_push( $home, array_pop($away ) );
}
}
return $round;
}
?>
roundrobinweboutout.php
<?php include "includes/db.php"; ?>
<?php include "roundRobinweb.php"; ?>
<?php
// create an array of teams
//$members = array('team1','team2','team3','team4', 'team5', 'team6', 'team7', 'team8', 'team9');
$sql = "SELECT * FROM teams";
$result = mysqli_query($connection, $sql);
$players = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)){
$players[] = $row;
}
}
//foreach ($players[0] as $player){
// echo $player['player'];
//}
foreach ($players as $player){
echo "<br> " . $player['player'] . "<br> ";
}
// do the rounds
//$rounds = roundRobin($members);
$rounds = roundRobin($players);
$table = "<table>\n";
foreach($rounds as $round => $games){
$table .= "<tr><th>Round: ".($round+1)."</th><th></th><th>Away</th></tr>\n";
foreach($games as $play){
$table .= "<tr><td>".$play["Home"]."</td><td>-vs-</td><td>".$play["Away"]."</td></tr>\n";
}
}
$table .= "</table>\n";
echo $table;
?>
OutPut:
Database connected
james
johns
petes
gregs
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
( ! ) Notice: Array to string conversion in C:\websites\schedule\roundRobinWebOutout.php on line 33
Call Stack
Time Memory Function Location
1 0.0023 403072 {main}( ) …\roundRobinWebOutout.php : 0
Round: 1 | Away | |
---|---|---|
Array | -vs- | Array |
Array | -vs- | Array |
Round: 2 | Away | |
Array | -vs- | Array |
Array | -vs- | Array |
Round: 3 | Away | |
Array | -vs- | Array |
Array | -vs- | Array |