Jump to content
Larry Ullman's Book Forums

Class Properties


Recommended Posts

Hi all,

 

I was wondering if class properties that are only assigned in a particular method belong only to that method. Like the

getC()

method and

insert()

method

$r, $t, $q are unique to each method is that correct to assume?

<?php
// comment (doT) php
//
class Comments extends database { // picture comments class im new to this OOP thing

protected $_picId;
protected $_comments;

function __construct($pic) {
$this->_picId = $pic;
$this->getC(); // returns all comments if there are any from database

} // construct on instantiation get all comments

protected function getC() { // gets comments from submitted picture id

$this->_picId = $pic; // $pic picture id from _GET array
$q = "SELECT comment_id, picture_id, DATE_FORMAT(comment_date, '%b %e %Y %r'), name_of_commentor, db, comment FROM db WHERE picture_id=$this->_picId";
$r = @mysqli_query($this->dbc, $q);
$t = mysqli_num_rows($r);
if ($t == 1) {
$this->_comments = mysqli_fetch_array($r, MYSQLI_ASSOC);
return $this->_comments;
} else {
return false;
}

} // end of getC function

protected function insert($picture_id, $noc, $bid, $comment) {

$p = mysqli_real_escape_string($this->dbc, $picture_id);
$n = mysqli_real_escape_string($this->dbc, $noc);
$b = mysqli_real_escape_string($this->dbc, $bid);
$c = mysqli_real_escape_string($this->dbc, $comment);
// this function inserts a comment of a picture in the database
$q = "INSERT INTO db (picture_id, comment_date, name_of_commentor, db_id, comment) VALUES ('$p', NOW(), '$n', '$b', '$c')";
$r = @mysqli_query($this->dbc, $q);
$t = mysqli_num_rows($r);
if ($t == 1) {
 return true;
} else {
 return false;
}
}
} // end of Comments class 

 

Thanks all in advanced

 

jAe pEe

Link to comment
Share on other sites

 Share

×
×
  • Create New...