html - White screen of death on dynamic sql php page -
i learning php creation of web pages mysql. wanted to run script, fails. white screen of death. can @ code , tell me , in direction should go. time.
<?php include 'include.php'; // php class bracket // bracket builder gotgames // author benjamin thomas // october 2009 class bracket { //bring in database details include.php var $username = db_user; var $password = db_pass; var $database = db_name; //init class variables var $tournament_name; var $tournament_size; var $tournament_format; var $tournament_id; var $result_servers; var $result_stvs; var $result_matches; var $result_teams; //************************************************************************************* // schedule bracket // input - tournament id used identify tournament scheduling // operation - constructor reads required information databas , assigns following class values: // tournament_name; // tournament_size; // tournament_format; // tournament_id; // result_servers; // result_stvs; // result_matches; // result_teams; //************************************************************************************* function bracket($tourn_id) { //save tournament id $this->tournament_id = $tourn_id; //collect required information draw bracket mysql_connect('localhost',$this->username,$this->password); @mysql_select_db($this->database) or die( "unable select database"); $query = "select * tms_tournament id = ".$tourn_id; $result_tournament = mysql_query($query) or die('error, query failed'); $row = mysql_fetch_assoc($result_tournament); $this->tournament_name = $row['name']; $this->tournament_size = $row['size']; $this->tournament_format = $row['format']; mysql_free_result($result_tournament); //read , save information database $query = "select * tms_servers id_tournament = ".$tourn_id; $this->result_servers = mysql_query($query) or die('error, query failed'); $query = "select * tms_stvs id_tournament = ".$tourn_id; $this->result_stvs = mysql_query($query) or die('error, query failed'); $query = "select * tms_matches id_tournament = ".$tourn_id; $this->result_matches = mysql_query($query) or die('error, query failed'); $query = "select * tms_teams_".$tourn_id." id_tournament = ".$tourn_id; $this->result_teams = mysql_query($query) or die('error, query failed'); } //************************************************************************************* // function draw // operation - called display single elimination bracket //************************************************************************************* function draw() { $total_rounds = log($this->tournament_size,2)+1; //total rounds $row = array(); $col = array($row); //create data type hold our bracket information //generate datastructure hold information required layout bracket for($i = 1; $i <= $total_rounds; $i++) { $round_matches = $this->getmatches($i); $matches = pow(2,$total_rounds-$i); //calc how many matches round $interval = pow(2,$i); // calc interval layout spacing $offset = pow(2,$i-1); // each round offset differnt amount form bracket pyramid for($c = 1; $c <= ($this->tournament_size*2)+1; $c++) { if ($c < $offset) { // blank space $col[$i][$c] = 0; } elseif ($c > (($this->tournament_size*2)+1)-$offset) { // blank space $col[$i][$c] = 0; } elseif ($c==$offset) { if ($i==$total_rounds) { //no match tournament winner $col[$i][$c] = "champion"; }else { //print team here $tmp_array=array_shift($round_matches); $col[$i][$c] = $tmp_array['print_team']; } } elseif ((($c-$offset) % $interval) == 0) { //print team here $tmp_array=array_shift($round_matches); $col[$i][$c] = $tmp_array['print_team']; } elseif ($c==($offset*2)) { //print match here $col[$i][$c] = "match".$tmp_array['id']; } elseif ((($c-$offset*2) % ($interval*2)) == 0) { //print match here $col[$i][$c] = "match".$tmp_array['id']; } else { $col[$i][$c] = 0; // blank space } print("<br>"); } // layout bracket using html tables , data struct created above: col print("<table width='100%' border='5'>"); print("<tr>"); for($i = 1; $i <= $total_rounds-1; $i++) { print("<th>round ".(string)$i."</th>"); } print("</tr>"); for($c=1;$c<=($this->tournament_size*2);$c++) { print("<tr>"); for($i = 1; $i <= $total_rounds+1; $i++) { if (strcmp(substr($col[$i][$c],0,5),"match")==0) { $tmp_array = $this->getmatch(substr($col[$i][$c],5)); $datetime = new datetime($tmp_array['timestamp']); print("<td align='center' bgcolor='#ffe4e1'><table><tr><td align='center'>".$datetime->format("d, js f y ga")."</td></tr><tr><td align='center'>stv - ".$this->getstvdetails($tmp_array['id_stv'])."</td></tr></table> </td>"); } elseif (strcmp(substr($col[$i][$c],0,5),"teams")==0) { print("<td align='center' bgcolor='#dddddd'>".$this->getteamname(substr($col[$i] [$c],5))."</td>"); } elseif ($col[$i][$c]) { print("<td align='center' bgcolor='#dddddd'>".$col[$i][$c]."</td>"); } else { print("<td height='40'></td>"); } } print("</tr>"); } print("</table>"); } } //************************************************************************************* // function getmatch // input - match_id // operation - retrives information saved parsed match_id //************************************************************************************* function getmatch($match_id) { $query = "select * tms_matches id = ".(string)$match_id; $result = mysql_query($query); $row = mysql_fetch_assoc($result); mysql_free_result($result); return $row; } //************************************************************************************* // function getteamname // input - team_id // operation - returns name of team parsed team id //*********************************************************************************** ** function getteamname($team_id) { $query = "select name tms_teams_".(string)$this->tournament_id." id = ".(string)$team_id;$result = mysql_query($query) or die('error, query failed'); return mysql_result($result, 0); } //************************************************************************************* // function getstvdetails // input - stv_id // operation - returns ip address of parsed stv id //************************************************************************************* function getstvdetails($stv_id) { $query = "select address tms_stvs id = ".(string)$stv_id; $result = mysql_query($query); return mysql_result($result, 0); } //************************************************************************************* // function getmatches // input round_no // operation - returns array of matches parse round. array sorted position field. //************************************************************************************* function getmatches($round_no) { $matches_avail = array(); $tmp_row = array(); $query = "select * tms_matches id_tournament = ".$this->tournament_id." , round = ".(string)$round_no." order position"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $tmp_row = $row; if ($row['status'] == 1) { $row = array_merge($row,array("print_team"=>"winner of ".$row['id_match_parent_a'])); } else { $row = array_merge($row,array("print_team"=>"teams".$row['id_team_a']));//team } $matches_avail[] = $row; $row = $tmp_row; if ($row['status'] == 1) { $row = array_merge($row,array("print_team"=>"winner of ".$row['id_match_parent_b'])); } else { $row = array_merge($row,array("print_team"=>"teams".$row['id_team_b']));//team b } $matches_avail[] = $row; unset($tmp_row); }return $matches_avail; } //************************************************************************************* // destructor // operation - frees memory held sql result sets //************************************************************************************* function __destruct() { mysql_free_result($this->result_servers); mysql_free_result($this->result_stvs); mysql_free_result($this->result_matches); mysql_free_result($this->result_teams); mysql_close(); } } ?>
i couldn't find issues, cleaned code, maybe find issue.
<?php include('include.php'); // php class bracket // bracket builder gotgames // author benjamin thomas // october 2009 class bracket { //bring in database details include.php var $username = db_user; var $password = db_pass; var $database = db_name; //init class variables var $tournament_name; var $tournament_size; var $tournament_format; var $tournament_id; var $result_servers; var $result_stvs; var $result_matches; var $result_teams; //************************************************************************************* // schedule bracket // input - tournament id used identify tournament scheduling // operation - constructor reads required information databas , assigns following class values: // tournament_name; // tournament_size; // tournament_format; // tournament_id; // result_servers; // result_stvs; // result_matches; // result_teams; //************************************************************************************* function bracket($tourn_id) { //save tournament id $this->tournament_id = $tourn_id; //collect required information draw bracket mysql_connect('localhost', $this->username, $this->password); @mysql_select_db($this->database) or die("unable select database"); $query = "select * tms_tournament id = " . $tourn_id; $result_tournament = mysql_query($query) or die('error, query failed'); $row = mysql_fetch_assoc($result_tournament); $this->tournament_name = $row['name']; $this->tournament_size = $row['size']; $this->tournament_format = $row['format']; mysql_free_result($result_tournament); //read , save information database $query = "select * tms_servers id_tournament = " . $tourn_id; $this->result_servers = mysql_query($query) or die('error, query failed'); $query = "select * tms_stvs id_tournament = " . $tourn_id; $this->result_stvs = mysql_query($query) or die('error, query failed'); $query = "select * tms_matches id_tournament = " . $tourn_id; $this->result_matches = mysql_query($query) or die('error, query failed'); $query = "select * tms_teams_" . $tourn_id . " id_tournament = " . $tourn_id; $this->result_teams = mysql_query($query) or die('error, query failed'); } //************************************************************************************* // function draw // operation - called display single elimination bracket //************************************************************************************* function draw( ) { $total_rounds = log($this->tournament_size, 2) + 1; //total rounds $row = array( ); $col = array( $row ); //create data type hold our bracket information //generate datastructure hold information required layout bracket for($i = 1; $i <= $total_rounds; $i++) { $round_matches = $this->getmatches($i); $matches = pow(2, $total_rounds - $i); //calc how many matches round $interval = pow(2, $i); // calc interval layout spacing $offset = pow(2, $i - 1); // each round offset differnt amount form bracket pyramid for($c = 1; $c <= ($this->tournament_size * 2) + 1; $c++) { if($c < $offset) { // blank space $col[$i][$c] = 0; } //$c < $offset elseif($c > (($this->tournament_size * 2) + 1) - $offset) { // blank space $col[$i][$c] = 0; } //$c > (($this->tournament_size * 2) + 1) - $offset elseif($c == $offset) { if($i == $total_rounds) { //no match tournament winner $col[$i][$c] = "champion"; } //$i == $total_rounds else { //print team here $tmp_array = array_shift($round_matches); $col[$i][$c] = $tmp_array['print_team']; } } //$c == $offset elseif((($c - $offset) % $interval) == 0) { //print team here $tmp_array = array_shift($round_matches); $col[$i][$c] = $tmp_array['print_team']; } //(($c - $offset) % $interval) == 0 elseif($c == ($offset * 2)) { //print match here $col[$i][$c] = "match" . $tmp_array['id']; } //$c == ($offset * 2) elseif((($c - $offset * 2) % ($interval * 2)) == 0) { //print match here $col[$i][$c] = "match" . $tmp_array['id']; } //(($c - $offset * 2) % ($interval * 2)) == 0 else { $col[$i][$c] = 0; // blank space } print("<br>"); } //$c = 1; $c <= ($this->tournament_size * 2) + 1; $c++ // layout bracket using html tables , data struct created above: col print("<table width='100%' border='5'>"); print("<tr>"); for($i = 1; $i <= $total_rounds - 1; $i++) { print("<th>round " . (string) $i . "</th>"); } //$i = 1; $i <= $total_rounds - 1; $i++ print("</tr>"); for($c = 1; $c <= ($this->tournament_size * 2); $c++) { print("<tr>"); for($i = 1; $i <= $total_rounds + 1; $i++) { if(strcmp(substr($col[$i][$c], 0, 5), "match") == 0) { $tmp_array = $this->getmatch(substr($col[$i][$c], 5)); $datetime = new datetime($tmp_array['timestamp']); print("<td align='center' bgcolor='#ffe4e1'><table><tr><td align='center'>" . $datetime->format("d, js f y ga") . "</td></tr><tr><td align='center'>stv - " . $this->getstvdetails($tmp_array['id_stv']) . "</td></tr></table> </td>"); } //strcmp(substr($col[$i][$c], 0, 5), "match") == 0 elseif(strcmp(substr($col[$i][$c], 0, 5), "teams") == 0) { print("<td align='center' bgcolor='#dddddd'>" . $this->getteamname(substr($col[$i][$c], 5)) . "</td>"); } //strcmp(substr($col[$i][$c], 0, 5), "teams") == 0 elseif($col[$i][$c]) { print("<td align='center' bgcolor='#dddddd'>" . $col[$i][$c] . "</td>"); } //$col[$i][$c] else { print("<td height='40'></td>"); } } //$i = 1; $i <= $total_rounds + 1; $i++ print("</tr>"); } //$c = 1; $c <= ($this->tournament_size * 2); $c++ print("</table>"); } //$i = 1; $i <= $total_rounds; $i++ } //************************************************************************************* // function getmatch // input - match_id // operation - retrives information saved parsed match_id //************************************************************************************* function getmatch($match_id) { $query = "select * tms_matches id = " . (string) $match_id; $result = mysql_query($query); $row = mysql_fetch_assoc($result); mysql_free_result($result); return $row; } //************************************************************************************* // function getteamname // input - team_id // operation - returns name of team parsed team id //*********************************************************************************** ** function getteamname($team_id) { $query = "select name tms_teams_" . (string) $this->tournament_id . " id = " . (string) $team_id; $result = mysql_query($query) or die('error, query failed'); return mysql_result($result, 0); } //************************************************************************************* // function getstvdetails // input - stv_id // operation - returns ip address of parsed stv id //************************************************************************************* function getstvdetails($stv_id) { $query = "select address tms_stvs id = " . (string) $stv_id; $result = mysql_query($query); return mysql_result($result, 0); } //************************************************************************************* // function getmatches // input round_no // operation - returns array of matches parse round. array sorted position field. //************************************************************************************* function getmatches($round_no) { $matches_avail = array( ); $tmp_row = array( ); $query = "select * tms_matches id_tournament = " . $this->tournament_id . " , round = " . (string) $round_no . " order position"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $tmp_row = $row; if($row['status'] == 1) { $row = array_merge($row, array( "print_team" => "winner of " . $row['id_match_parent_a'] )); } //$row['status'] == 1 else { $row = array_merge($row, array( "print_team" => "teams" . $row['id_team_a'] )); //team } $matches_avail[ ] = $row; $row = $tmp_row; if($row['status'] == 1) { $row = array_merge($row, array( "print_team" => "winner of " . $row['id_match_parent_b'] )); } //$row['status'] == 1 else { $row = array_merge($row, array( "print_team" => "teams" . $row['id_team_b'] )); //team b } $matches_avail[ ] = $row; unset($tmp_row); } //$row = mysql_fetch_assoc($result) return $matches_avail; } //************************************************************************************* // destructor // operation - frees memory held sql result sets //************************************************************************************* function __destruct( ) { mysql_free_result($this->result_servers); mysql_free_result($this->result_stvs); mysql_free_result($this->result_matches); mysql_free_result($this->result_teams); mysql_close(); } } ?>
Comments
Post a Comment