Search the Community
Showing results for tags 'methods'.
-
I'm really confused and hoping someone can point me in the right direction. I feel this is one of those really simple things that I'm going to want to slap myself in the head over when it's resolved. It simply involves displaying a comment count in a certain area of my project. I have this method to display comments here -> <?php public function display($post_id) { $rule = "AND comment_status='approved' ORDER BY date_added DESC"; $field = "post_id"; $query = $this->_db->get(self::$_table, array($field, "=", $post_id), $rule); $this->_data = $query->all(); $this->_count = count($this->_data); $cnt = 0; foreach($this->_data as $obj) { $data = array( "id" => $obj->id, "post_id" => $obj->post_id, "commenter" => $obj->username, "comment" => $obj->body, "date" => date("F d, Y H:i:s", strtotime($obj->date_added)), "profile_pic" => $this->_user->profilePic($obj->username), ); echo HTML::comments($data, $cnt); $cnt++; } echo $this->count(); // JUST HERE FOR TEST PURPOSES } public function count() { return $this->_count; } The line that's commented for FOR TEST PURPOSES displays the comment count as expected. The issue arises when I port it to the display page. <h5 class="title"><?php echo $comment->count(); ?> Comments</h5> I get no error, but I get no number for the comment count either. I don't understand why. I've obviously done the instantiation at the top, I didn't overlook that (represented by $comment). As the count stands right now it should say '2 Comments'. The $this->count() test line works, why am I getting no result where it matters?
-
Good evening, Phreaks. Quick question. I have this method here -> public function get($table, $where = [], $column = "*") { return $this->action("SELECT {$column}", $table, $where); } It works great as long as the call to it includes the $where array. I want both $where and $column to be optional here and $where to be an array when it's included. if I only use the $table parameter (which is the only one I want to be required). I keep getting a Could one of you fine folks please explain to me about this error and why I need the $where parameter when I want it to be optional. Thank you
-
I'm looking for some insight on where/how to look something up. I have a Post class and it's really messy so I'm trying to clean it up. There's a method - createPost() - that takes in 8 parameters from a form, does what's needed to them to prepare them for database and creates 7 more properties, as well. For a total of 15 fields being sent to the database. I want to create a sendPost() method to handle this. In creating this method I realized that all these parameters look and feel burdensome and there's no real connection between the 2 methods other than sharing a class. I'd like to look into how to make sendPost take however many of parameters from whichever method it's called for without always having to pass the same amount. So for example if sendPost is being called with createPost than it has to handle 15 parameters, but, later, if I want to call sendPost on an editPost method, for example, it may only need to send 6 parameters back to the database meaning the other 9 would have to be redundantly passed again. I seem to recall from Python years ago there was a way to do this but I can't remember and I really don't know what to even search for to research it. Any direction or resources or advice that anyone could share would be really helpful and appreciated. Thanks
-
I've been scrolling through some 3rd party code trying to get ideas and a deeper understanding of PHP. I came across these 2 simple methods in a class entitled 'Category' -> public function deleteCategory($id) { $query = mysqli_query($this->conn, "DELETE FROM top_categories WHERE top_cat_id=$id"); if($query) { return true; } else { return false; } } public function updateCategory($id, $category) { $query = mysqli_query($this->conn, "UPDATE top_categories SET top_cat_title='$category' WHERE top_cat_id=$id"); if($query) { return true; } else { return false; } } They're simple enough and work perfectly in the context of their functionality, but I don't understand how. Their instantiation and calls are ordinary but I don't understand how they do what they do. To me (a very untrained eye) they look like they initialize a variable ($query) and then check if it's initialized or not without actually doing anything with it. They've both been instantiated in a file that is included at the top of each page and the method calls are seemingly normal -> if(isset($_POST['edit_cat'])) { $cat_obj->updateCategory($cat_id, $_POST['cat_title']); header("Location: category.php?message=category-updated"); } if(isset($_GET['cat_id'])) { $cat_obj->deleteCategory($_GET['cat_id']); header("Location: category.php?message=deleted-successfully"); } Can someone with the time and will please explain how these 2 methods do the things they do?
-
I have to write small segment of PHP code to print the word(s) 'Hello, World!' in uppercase letters, I have thus far wrote a small section of code that prints the output 'Hello, World!'. But, I'm completely stuck on how to make the letters all uppercase?!?? Moreover; that strtoupper goes somewhere in there right? <?php class TextFunctions { public static $string = 'Hello, World!'; static public function strtoupper() { } } echo TextFunctions::$string; ?>