2025-03-14 19:51:14 -04:00
< ? php
session_start ();
include ( " ../admin/db_config.php " );
try { // Try opening the SQL database connection
$conn = new PDO ( " mysql:host= $servername ; dbname= $dbName " , $dbUsername , $dbPassword );
// set the PDO error mode to exception
$conn -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION );
// Get the division from the page
$division = $_GET [ " division " ];
// If we want all the data, we don't need to select a division in the SQL query
if ( $division == " all " ) {
2025-03-15 11:26:43 -04:00
$sqlGetTourneyInfo = $conn -> prepare ( " SELECT tournamentUID,tournamentName,tournamentDate,tournamentDivision,numPlayers,winningTeamName,winner1,winner2,winner3,winner4 FROM " . $tournamentDataTableName . " ORDER BY tournamentDate DESC LIMIT $tourneyCardLimit " );
2025-03-14 19:51:14 -04:00
} else {
2025-03-15 11:26:43 -04:00
$sqlGetTourneyInfo = $conn -> prepare ( " SELECT tournamentUID,tournamentName,tournamentDate,tournamentDivision,numPlayers,winningTeamName,winner1,winner2,winner3,winner4 FROM " . $tournamentDataTableName . " WHERE tournamentDivision=' " . $division . " ' ORDER BY tournamentDate DESC LIMIT $tourneyCardLimit " );
2025-03-14 19:51:14 -04:00
}
$sqlGetTourneyInfo -> execute ();
} catch ( PDOException $e ) { // failed connection
echo " Connection failed: " . $e -> getMessage ();
}
$tourneyResults = $sqlGetTourneyInfo -> fetchAll ( PDO :: FETCH_ASSOC );
?>
< html >
< head >
< meta charset = " UTF-8 " />
< meta name = " viewport " content = " width=device-width, initial-scale=1, user-scalable=no " />
< link rel = " stylesheet " href = " /styles/primary.css " />
< link rel = " stylesheet " href = " /styles/db_management.css " />
2025-03-15 07:22:57 -04:00
< link rel = " stylesheet " href = " /styles/tourney_cards.css " />
2025-03-14 19:51:14 -04:00
< script src = " /scripts/tools.js " ></ script >
< script > verifyPageInFrame () </ script >
< title > no title </ title >
</ head >
< body >
< div class = " recentTourneyResultsPanel " >
< ? php
foreach ( $tourneyResults as $result ) {
$tourneyName = $result [ " tournamentName " ];
$tourneyDate = $result [ " tournamentDate " ];
2025-03-15 11:26:43 -04:00
$tourneyUID = $result [ " tournamentUID " ];
2025-03-15 07:09:55 -04:00
$division = ucfirst ( $result [ " tournamentDivision " ]);
2025-03-14 19:51:14 -04:00
$numPlayers = $result [ " numPlayers " ];
$winningTeamName = $result [ " winningTeamName " ];
$winner1 = $result [ " winner1 " ];
$winner2 = $result [ " winner2 " ];
$winner3 = $result [ " winner3 " ];
$winner4 = $result [ " winner4 " ];
// Format date
$tourneyDate = DateTime :: createFromFormat ( 'Y-m-d' , $tourneyDate );
$tourneyDate = $tourneyDate -> format ( 'M j, Y' );
echo ( "
< div class = \ " tourneyCard \" >
2025-03-15 11:26:43 -04:00
< p class = \ " tourneyCardHeader \" ><a href= \" /tournament/ $tourneyUID\ " class = \ " plainLinkBlack \" onclick= \" redirect('this', '/tournament/ $tourneyUID '); \" > $tourneyName </a></p>
2025-03-14 19:51:14 -04:00
< p class = \ " newLineThin \" ></p>
< p class = \ " tourneyCardLeft \" > $tourneyDate </p>
< p class = \ " tourneyCardRight underlined \" > $winningTeamName </p>
< p class = \ " newLineThin \" ></p>
< p class = \ " tourneyCardLeft \" > $division </p>
< p class = \ " tourneyCardRight \" ><a href= \" /user/ $winner1\ " class = \ " plainLinkBlack \" onclick= \" redirect('this', '/user/ $winner1 '); \" > $winner1 </a></p>
< p class = \ " newLineThin \" ></p>
< p class = \ " tourneyCardLeft \" > " . $numPlayers . " v " . $numPlayers . " </p> " );
if ( $numPlayers >= 2 ) {
echo " <p class= \" tourneyCardRight \" ><a href= \" /user/ $winner2\ " class = \ " plainLinkBlack \" onclick= \" redirect('this', '/user/ $winner2 '); \" > $winner2 </a></p> " ;
}
echo " <p class= \" newLineThin \" ></p> " ;
if ( $numPlayers >= 3 ) {
echo ( "
< p class = \ " tourneyCardLeft \" ></p>
< p class = \ " tourneyCardRight \" ><a href= \" /user/ $winner3\ " class = \ " plainLinkBlack \" onclick= \" redirect('this', '/user/ $winner3 '); \" > $winner3 </a></p>
< p class = \ " newLineThin \" ></p> " );
}
if ( $numPlayers == 4 ) {
echo ( "
< p class = \ " tourneyCardLeft \" ></p>
< p class = \ " tourneyCardRight \" ><a href= \" /user/ $winner4\ " class = \ " plainLinkBlack \" onclick= \" redirect('this', '/user/ $winner4 '); \" > $winner4 </a></p>
< p class = \ " newLineThin \" ></p> " );
}
echo ( " </div>
< p class = \ " newLineThin \" > </p>
" );
}
?>
</ div >
</ body >
</ html >