Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Did I write this OOP class correctly?

Here's my code:

<?php
class SongwritingWinner {
public $the_winner_date;
public $the_winner_type;

	function the_winner(){
	$bruce = "select * from songwriting_winners where contestant_id='_GET[id]' order by winner_date";
	$bruce_query=mysqli_query($cxn, $bruce);
	$bruce_count=mysqli_num_rows($bruce);
		if($bruce_count>1)
		{
		$michelle= "select * from songwriting_winners where contestant_id='$_GET[id]' order by winner_date DESC LIMIT 1";
		$michelle_query=mysqli_query($cxn, $michelle);
		$michelle_row=mysqli_fetch_assoc($michelle);
		$this->the_winner_date=date("m/d/Y", strtotime($michelle_row['winning_date']));
		$this->the_winner_type = $michelle_row['winner_type'];
		}
		if($bruce_count>0 and $bruce_count<2)
		{
		$michelle= "select * from songwriting_winners where contestant_id='$_GET[id]' order by winner_date DESC LIMIT 1";
		$michelle_query=mysqli_query($cxn, $michelle);
		$michelle_row=mysqli_fetch_assoc($michelle);
		$this->the_winner_date=date("m/d/Y", strtotime($michelle_row['winning_date']));
		$this->the_winner_type = $michelle_row['winner_type'];
		}
		if(!$bruce_count>0)
		{
		$this->the_winner_date=date("m/d/Y");
		$this->the_winner_type="";
		}
	}

}

?>

Open in new window


This is my first crack at OOP and I want to think that I'm close, but I'm not there yet. Reason being is that when I go to instantiate my class and attempt to retrieve a variable, I get nothing.

Here's the way I'm calling the class...

	<?php 
							require_once('classes/songwriting_class.php'); 
							$dean = new SongwritingWinner();
							echo $dean->the_winner_date;
							?>

Open in new window


No errors, but no data. What am I doing wrong?
Avatar of mastoo
mastoo
Flag of United States of America image

I'm not a php person, but it looks like you have a class with a method called the_winner.  You haven't called that method anywhere.  That method seems to initialize the_winner_date, so if you don't call it you're not going to get a meaningful value.
SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would recommend a brilliant series of OOP tutorials here:
http://jream.com/learning/videos/php-oop
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial