OOP newbie
Posted: Mon Jan 25, 2010 2:45 pm
Hello everyone and TY in advance for any help/suggestions. I have alot of code on my baseball site that is function based only. My goal is to advance to the next level of PHP programming, ie, OOP. I have read several books, online tuts, etc, etc. I now want to take "baby steps into the code and have a sample I'd like to post. The class is going to be a basic database search and display what it finds. I later want to fine tune different types of displays. My sample code is the first step in setting up my array of games (and scores if present in the scores db). Just not sure on how to work with arrays within a class (from one method to another). I understand a regular $this-> expression.
TY
Code: Select all
class DisplayGames{
public $season;
public $league;
public $DisplayType;
function __construct ($season, $league){
$this->season = mysql_real_escape_string($season); //edited after reply
$this->league = mysql_real_escape_string($league); //edited after reply
}
function set_season($new_season) {
$this->season = $new_season;
}
function set_league($new_league) {
$this->league = $new_league;
}
function find_GamesScores(){
$games=array();
$query_sch = "SELECT * FROM ".$this->league."_schedule".$this->season." order by game_date";
$query_sco = "SELECT * FROM ".$this->league."_scores".$this->season;
$schedule_query = mysql_query ($query_sch);
$scores_query = mysql_query ($query_sco);
if($number_of_results_scores == 0 ){
return false;
}
$result_schedule = result_to_array($schedule_query);
$result_scores = result_to_array($scores_query);
foreach($result_schedule as $rsch):
foreach($result_scores as $rsco):
if ($rsco[0] == $rsch[0]){
$games[$rsch[0]][0]=$rsch[0];//game_id
$games[$rsch[0]][1]=$rsch[1];//game_date
$games[$rsch[0]][2]=$rsch[2];//game_park
$games[$rsch[0]][3]=$rsch[3];//game_vis
$games[$rsch[0]][4]=$rsch[4];//game_home
$games[$rsch[0]][5]=$rsch[5];//game_week
$games[$rsch[0]][6]=$rsco[1];//game_vis1 score
$games[$rsch[0]][7]=$rsco[2];//game_home1 score
$games[$rsch[0]][8]=$rsco[3];//game_vis2 score
$games[$rsch[0]][9]=$rsco[4];//game_home2 score
$games[$rsch[0]][10]=$rsco[5];//game_status1
$games[$rsch[0]][11]=$rsco[6];//game_status2
}
endforeach;
endforeach;
$this->games = $games; //edited after reply
return $this->games; //edited after reply
}//end find_GamesScores
function result_to_array($result){
$res_array = array();
for ($count=0; $row = mysql_fetch_array($result); $count++){
$res_array[$count] = $row;
}
return $res_array;
}
} // end class