Jump to content

Search the Community

Showing results for tags 'class'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 7 results

  1. 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
  2. Hi Freaks, I've been trying to put together subscribe functionality on a project. Been at it for hours and can't make any progress. The categories that a user is subbed to are stored in comma separated string in the database and pulled out into $_SESSION['user_subs'] I have these 2 methods here to start -> <?php private function userSubscribed($cat_id) { $category = $this->getCategoryByID($cat_id); if(in_array($category, $_SESSION['user_subs'])) { echo "user subscribed"; return true; } else { echo "user NOT subscribed"; return false; } } public function displaySubscribedButton($cat_id) { $subscribed = $this->userSubscribed($cat_id); if($subscribed) { $action_btn = "<td><a href='category_posts.php?cat_id=$cat_id' name='sub_btn' class='btn btn-secondary'>Unsubscribe</a>"; } else { $action_btn = "<td><a href='category_posts.php?cat_id=$cat_id' name='sub_btn' class='btn btn-danger text-color- primary'>Subscribe</a>"; } return $action_btn; } They've both been well tested and I know they're working correctly. Then I have this one (which is the problem child) -> <?php public function updateSubscriptionCategory($cat_id, $username) { $category = $this->getCategoryByID($cat_id); $subscribed = $this->userSubscribed($cat_id); print_r($_SESSION['user_subs']); if($subscribed){ unset($_SESSION['user_subs'][$category]); $subs = $_SESSION['user_subs']; $subscribed = false; } else { $new_sub = ",".$category; $subs = array_push($_SESSION['user_subs'], $new_sub); $subscribed = true; } $stmt = $this->conn->prepare("UPDATE ".User::$table." SET subs=? WHERE username=?"); if($stmt) { $stmt->execute([$subs, $username]); } else { echo "you fucked up"; } } I call it from the category file, here -> <?php require_once("assets/initializations.php"); $post_obj = new Post($conn, $username); $cat_obj = new Category($conn, $username); $cat_id = $_GET['cat_id']; if(isset($_POST['sub_btn'])) { $cat_obj->updateSubscriptionCategory($cat_id, $username); // header("Location: category_posts.php?cat_id=$cat_id&cat_title=$cat_title"); } but the page only reloads no changes are made not on the page nor in the db nor do I get any feedback, not from the 'print_r' or the else at the bottom. I feel like it's not even running this method. Was hoping that someone sees something that I've been missing. 8 hours in and I'm still not able to get it to work. TIA for all input
  3. Hi guys, I am trying to calculate hours a person works by calculating the values of text fields in a form. However, when I load the page I get "Class 'times_counter' not found. Here is the calculation code" if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += @$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes; } } public function get_total_time(){ return $this->totaltime; } } $times = array( $mondiff->format('%H:%I'), $tudiff->format('%H:%I'), $weddiff->format('%H:%I'), $thdiff->format('%H:%I'), $fridiff->format('%H:%I'), $satdiff->format('%H:%I'), $sundiff->format('%H:%I'), ); $counter = new times_counter($times); I had this on an old project, which I no longer have but it worked then. Any ideas?
  4. Hi, I've inherited some code on a system from another person. I'll be the first to admit that I'm not a PHP pro, I am self taught, and use it sparingly for personal projects mainly. So this is a bit beyond my skill level, and I was hoping for some advice: The system is a glorified calendar, with a lot of our own data being slapped on top of it and presented nicely. The issue I have thoguh is that due to the way the calendar is generated, I cant make the height of the days move dynamically based on what content gets dropped into each day on the calendar. If one day is busy and has 8 events drop into it, they will overflow the days cell. I wanted to adjust the height of ALL cells on a month view calendar to the heighest required height of all cells in that view. What I was going to do, is +1 to a coutner for every event (or block) that is generated for each day (days are looped through a private function), and commit that number to an array. At the end fo the loop (after all days ahve been counted and have a value in the array), I was going to use max() on the array, pull the largest number, calculate the days cell hiehgt from that and apply it via CSS at page level. I've summarised the code in effect here (psuedo code, not real PHP): class Calendar { public $heights; private fucntion dayLoop($cellNumber) { $heights = []; //array $block_count = 0; //counter while(mysqlrowdata) { [code for mysql operations] $block_count++; //increment the count } $day_height = ($block_count * 16) + 18; //do some math specific to my application $this->heights[] = $day_height; //commit calc'd value to array //array_push($heights, $day_height); //this was a previosu attempt, i dont think i should use array_push here..?? } } That function, and others is called from the front end pages to generate the calendar. If I do a: var_dump($heights); after it on that page, all I get returned on screen is "Array ( )" I tried changing the private function to a public one, but this did not affect the outcome. Anyone have any ideas on what I'm doing wrong? Is my logic sound? Can I commit values to an array inside a loop in a public OR private function and then reference that array outside of the loop? I defined $heights as public in the class too, but that didnt change the outcome either. Thanks.
  5. I'm suddenly having trouble using my connection to my MySQL database... (yes it was working but now...) I have the Connection created in an include file and stored in variable $DB, in the main file that includes the file containing the$DB there are other includes for classes. These classes are SUPPOSED to use $DB to connect to and SELECT/UPDATE/INSERT, but for a reason I cant figure out they suddenly stopped seeing $DB. it keeps saying its an undefined variable. If you need to see code I can post...
  6. Hello, My first question is; if there is a class, and i dont want this class to be instantiated anywhere? How can i do this? What are the ways/keywords for this? My second question is; Are there type of classes that can't be instantiated? What are the names of these classes? Thanks in advance.
  7. class foo { // was this always allowed? public $bar = 'abc default value'; // or did older versions only allow this? public $bar; } I couldn't determine the answer to this question looking at documentation. I found some old code where no class had a default value. Maybe it was a developer preference, but I was wondering if older PHP versions didn't even allow default values? Just a question of curiosity.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.