Jump to content
Larry Ullman's Book Forums

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 post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...