Jump to content

Search the Community

Showing results for tags 'class'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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 (PhpStorm, VS Code, 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

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 9 results

  1. I had such a class : class NodeElement { no; x; y; tre; tdno; tdx; tdy; cbox; nodesArray; nodesTable; selected; constructor( x, y,nodesArray, nodesTable) { nodeCounter++; this.no = nodeCounter; this.x = x; this.y = y; this.nodesArray = nodesArray; this.nodesTable = nodesTable; //create elements this.tre = document.createElement("tr"); this.tre.id = "row"+this.no; this.tdno = document.createElement("td"); this.tdno.id = this.no; this.tdno.innerHTML = this.no; this.cbox = document.createElement("input"); this.cbox.type="checkbox"; this.cbox.id="cbox"+this.no; this.cbox.value=this.no; this.cbox.name="cbox"+this.no; this.cbox.setAttribute('onclick','select(this)'); this.tdx = document.createElement("td"); this.tdx.id="tdx"+this.no; this.tdx.innerHTML = this.x; this.tdy = document.createElement("td"); this.tdx.id="tdy"+this.no; this.tdy.innerHTML = this.y; } } I want to pass complete class object(i.e instantiated one) to a function select() as parameter when I click(i.e. checked the checkbox object of the class instance). My question is that line : this.cbox.setAttribute('onclick','select(this)'); I tried that too : this.cbox.setAttribute('onclick','select("'+this+'")'); but not worked. I could no achieve to pass neither checkbox nor the class object(NodeElement) to function select() as parameter. How can I do that?
  2. 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
  3. 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
  4. 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?
  5. I've got a bit of jQuery that is getting the bit of data that I want to search the page for. This is posted below. $(".pagelink").click(function(){ var myClass = this.className; var number = myClass.substr(myClass.length - 1); }); This bit is working ok. It gets the last bit of the element's class name which is a number incremented by the PHP that echoes it out. Now I want to search the page for a div that has a class that contains that var number. There will be a div somewhere on the page with a class that contains that number. It will be called either row0, row1, row2, row3 etc etc. The div is not a descendant element of the pagelink class, it is somewhere else so I don't think the find() variable is suitable. Any help will be greatly appreciated, thanks!
  6. I have two questions relating to each other which are regarding - both function __autoload and adding products to a class? Code for an autoload function (please see code #1), the output prints - but also gives an error message? Moreover, I also receive the notification in my php editor "class 'ooo' not found"? If I may ask a silly question I have noticed some autoload fucctions have implode and explode - how would I write one of these? The output and error: My Antonia: Willa Cather (5.99) Fatal error: Class 'ooo' not found in C:\ Code#1: <?php // we've writen this code where we need function __autoload($classname) { $filename = "./". $classname .".php"; include_once($filename); } // we've called a class *** $obj = new ooo(); ?> ------------------------------------------------------------------------------------------------------------------------------ How would I add more products to this product class? code#2: <?php class shopProduct { public $title; protected $producer = []; public $price; public function __construct($title, $producerName1, $producerName2, $price) { $this->title = $title; $this->producer[] = $producerName1; $this->producer[] = $producerName2; $this->price = $price; } public function getProducer() { return implode(' ', $this->producer); } } class ShopProductWriter { public function write ($shopProduct) { $str = "{$shopProduct ->title}: " . $shopProduct -> getProducer() . " ({$shopProduct -> price})\n"; print $str; } } $product1 = new ShopProduct("My Antonia", "Willa", "Cather", 5.99); $writer = new ShopProductWriter(); $writer -> write($product1); ?>
  7. 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; ?>
  8. I have been using the below method to access my database for some time now and just wanted to make sure im doing the correct thing. My application runs perfectly but im just trying to improve my programming skills. The classes are all loaded in with an autoloader so in theory using the classes below I could just call: echo User::getUsername(1); Like I say it works fine I would just love some feedback about what other people do and suggestions on something that might run better or looks cleaner. class Db { private static $db_read; private static $db_write; public static method read(){ if( self::$db_read == null ){ //create new database connection is it doesnt exist self::$db_read = new PDO(); } return self::$db_read; } public static method write() { if( self::$db_write == null ){ //create new database connection is it doesnt exist self::$db_write = new PDO(); } return self::$db_write; } class User { public static function getUsername($user_id){ $d = Db::read()->prepare('select * from user where id = ? '); $d->execute( array($user_id) ); $user = $d->fetch(); return $user['username']; } }
  9. I am using parent::__construct() in almost every classes to connect Mysql DB. Example class class secondClass extends dbconnect { public function __construct() { parent::__construct(); dbconnect class class dbconnect { private $mysqli_handler; public function __construct() { try { mysqli_report(MYSQLI_REPORT_STRICT); $this->mysqli_handler = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DBNAME); } catch (mysqli_sql_exception $e) { throw new Exception('Error: Could not make a database link using ' . DB_USERNAME . '@' . DB_HOSTNAME . '!'); } if ($this->mysqli_handler->connect_error) { trigger_error('Error: Could not make a database link (' . $this->mysqli_handler->connect_errno . ') ' . $this->mysqli_handler->connect_error); } $this->mysqli_handler->query("SET NAMES 'utf8'"); $this->mysqli_handler->query("SET CHARACTER SET utf8"); $this->mysqli_handler->query("SET CHARACTER_SET_CONNECTION=utf8"); $this->mysqli_handler->query("SET SQL_MODE = ''"); $this->mysqli_handler->query("SET time_zone = 'Asia/Kolkata'"); } Is this create multiple instance of mysql dbconnection? I am frequently getting mysql connection error on my shared hosting. If so how to avoid? I am using PHP Version 7.4.16, some detailed explanation will be useful for me as I am using like this for many projects. Thank you for your time. Prabakaran
×
×
  • 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.