Bruce Gust
asked on
Did I write this OOP class correctly?
Here's my code:
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...
No errors, but no data. What am I doing wrong?
<?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="";
}
}
}
?>
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;
?>
No errors, but no data. What am I doing wrong?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would recommend a brilliant series of OOP tutorials here:
http://jream.com/learning/videos/php-oop
http://jream.com/learning/videos/php-oop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.