Jump to content

Search the Community

Showing results for tags 'objects'.

  • 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 4 results

  1. Hi Phreaks, I hope you've all made it through the weekend with sound body and mind. The following 2 methods have been working together harmoniously for quite a while: <?php public function action($action, $table, $where = [], $rule = "") { if(count($where) === 3) { $operators = array('=', '<', '>', '<=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { if($rule == "") { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; } else { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ? {$rule}"; } if(!$this->query($sql, array($value))->error()) { return $this; } } return false; } public function get($table, $where = [], $rule = "", $column = "*") { return $this->action("SELECT {$column}", $table, $where, $rule); } My original belief was that it was easily extensible. I'm now to the point I'm trying to do that and receiving behaviour that I don't understand. If the action() method becomes thus -> <?php public function action($action, $table, $where = [], $rule = "") { if(count($where) === 3) { $operators = array('=', '<', '>', '<=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { if($rule == "") { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; } else { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ? {$rule}"; } if(!$this->query($sql, array($value))->error()) { return $this; } } } else { $sql = "{$action} FROM {$table}"; echo "this <br>"; return $this; } echo "false <br>"; return false; } with the added else{} statement to handle queries without WHERE conditions, and call it with just the $table parameter -> <?php public function get() { // $table = "posts"; $table = "categories"; $field = "*"; $query = $this->_db->get($table); // print_r($query); var_dump($query); } //normally, using conditions, it would look like this: $query = $this->_db->get($table, array($field, "=", $value); It returns: which we can see is picking up my else{} statement as it should but is returning this empty object. Could someone explain this to me? thank you
  2. Q: Should instancing an object be held off until needed - or - instanced early and held in memory until (it may/or may not) be called? Here is an example of the type situation where an custom error reporting class is instanced only when some test has failed. The error reporting is for authorized users running an application from protected sub sections(RESTish solution). /* * check form input and $_FILES upload * if test fails, instance errorwrapper::factory object and call errorReport method * testfilesize function, compares file size limit, set pass1 to true on success * testfiletype function, compares file to allowed MIME types, set pass2 to true on success * svalidate returns array $filteres, sanitized input on success, error message(s) on fail * param boolean $pass[1,2], set initial test condition * param int MAX_FILE_SIZE, constant defines max file size allowed. */ $pass1 = false; $pass2 = false; if(isset($_FILES)) { $ftype = $_FILES['img_file']['type']; $fsize = $_FILES['img_file']['size']; testfilesize($pass1,MAX_FILE_SIZE,$fsize); testfiletype($pass2,$ftype); } if($pass1 == false) { $erparams=array('cat'=>3,'src'=>"addform_control",'ref'=>"addform",'fault'=>"over file size limit"); $errObj=errorwrapper::factory($erparams); $errObj->errorReport(); exit(); } elseif ($pass2 == false) { $erparams=array('cat'=>3,'src'=>"addform_control",'ref'=>"addform",'fault'=>"illegal file type"); $errObj=errorwrapper::factory($erparams); $errObj->errorReport(); exit(); } /* * process form input, all fields checked before returning filteres * could report multiple errors, mode sets level of sanitization. */ $filteres = svalidate($_POST,$mode=1); if($filteres['exit']==1) { foreach($filteres['err'] as $err) { $mes .= $err."\n"; } $erparams=array('cat'=>2,'src'=>"addfo",'ref'=>"list_viewer",'fault'=>$mes); $errObj=errorwrapper::factory($erparams); $errObj->errorReport(); exit(); } else { //continue processing here, error checking over } In this case, the object $errObj is only instanced on a failed condition. However, $errObj could be instantiated before the conditional test and only calls the method when there is a failed condition. It seems like "six to one half dozen" but these applications are large and complex, so I'm looking to squeeze out any worthwhile optimization. Thanks for considering the question.
  3. My code; $sql = "SELECT SUM(IF(`submitdate` IS NULL , 1 , 0 )) as 'Survey Started But Not Completed' FROM `survey_$surveyid`"; $statement = $dbh->prepare($sql); $statement->execute(); $result = $statement->fetch(PDO::FETCH_OBJ); //pass that data to an object Is returning; stdClass Object ( [Survey Started But Not Completed] => )  I need to set this to a vaule that I can actually print out on the screen... Like a "0" for example. At the moment it is just a NULL. How do I do this?? These don't work; $result = 0; $result = array(['Survey Started But Not Completed'] => "0");
  4. I think I'm starting to wrap my mind around how to work with OOP - Objects and Arrays I have starting a small test php file that I'm doing testing on. Here's my main file <?php require('includes/Connect.MySQL.Class.php'); ?> <?php require('includes/TopicFileClass.php'); ?> <?php $data = array(); // New instance/modifier of class MemberTopic $topic = new MemberTopic($data); // Retrieve topics from mysqli database $topic = $topic->retrieve_record(); //print_r($topic); ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Object Oriented Programming</title> </head> <?php ?> <body> <?php foreach ($topic as $key=>$record) { // Loop through the Array to pull out the objects(records)?> <h1><?php echo $record->blog_name; // Display the Title of the Blog ?></h1> <p><?php echo $record->content; // Display the Content of the Blog ?></p> <?php } // Closes the foreach loop ?> </body> </html> An here is where I retrieve my data <?php require_once ("Connect.MySQL.Class.php"); class MemberTopic extends ConnectMySQLClass { protected $threads = array(); protected function main_record() { $database = parent::connect(); //Connects to the mysqli Database $query = "SELECT * FROM pages ORDER by id"; $result = $database->query($query); while ($page = $result->fetch_array(MYSQLI_ASSOC)) { $this->threads[] = (object) $page; } /* free result set */ $result->free(); //print_r($this->threads); return $this->threads; } public function retrieve_record() { //return $records = $this->assign_topic_record(); return $this->main_record(); } } My questions is there a way to make it so I have each object tied to a user name instead of a number? I tried doing $this->threads[$page['username']] = (object) $page; which only worked partially for it skip a few records(objects). If there isn't a way of doing it, it's no big deal for this has simplified my code a lot and makes it so much easier following what the code is doing. Thanks John
×
×
  • 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.