Jaepee 15 Posted August 2, 2012 Report Share Posted August 2, 2012 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 Quote Link to post Share on other sites
Richard_S 0 Posted August 2, 2012 Report Share Posted August 2, 2012 You are correct in saying that within each method the value/s of $r, $t and $q will be unique to the specific method. They are not however class properties, $_picID and $_comments are Quote Link to post Share on other sites
Jaepee 15 Posted August 2, 2012 Author Report Share Posted August 2, 2012 Thank you very much Richard. I'm just starting out with OOP and writing classes along with functions. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.