Jump to content

NotSureILikePHP

Members
  • Posts

    40
  • Joined

  • Last visited

NotSureILikePHP's Achievements

Member

Member (2/5)

0

Reputation

  1. We have hundreds of customers but half of them aren't active. We even have test customers that show up in the result list. So I created a column in the database for isActive and set the active customers to 1 and non active to 0. I want to load the active customers by default because we rarely need to do anything with the inactve but sometimes they need to edit them or reactivate them so here's what I want to do: //obviously not real code but this is for simplicity. The actual code is much longer so I am simplifying. customers = getCustomers for (custs as cust) if chkActive = checked && cust.active = false //skip this record when check active continue
  2. I also tried this: $active = '<script type="text/javascript">document.getElementByID("chkActive").checked;</script>'; Which almost worked. I got this response: Active Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked Checked But the page was greyed out and I had to refresh the page to do anything. It is in a loop so I would expect the mutiple Checked but I would expect this to be my resut. Active Checked Active Checked Active Checked Active Checked Active Checked Active Checked Active Checked Active Checked Active etc....
  3. Okay so I have a checkbox that by default I want to be checked and when it's checked it only searches for active customers. When you uncheck it it searches for all customers. How do I get the value of the checkbox? I found this snippet of code online: Active: <input type='checkbox' name='chkActive' value='1'> $active = isset($_POST['chkActive']) && $_POST['chkActive'] ? "1" : "0"; However this seems to only check the value on the postback. How do you get the value on load. Is there a document.getElementById equivilant in php or another simple way to just get the value of a checkbox?
  4. Okay this should be extremely simple and maybe I'm an idiot or just forgetting something simple. It has been a while since I programmed and never in PHP. I am working on an open source project where the coders are horrible and they create a paging object to go to page 2 or page 3 or whatever page you click on. However they never remove old variables in the url so for example if I click on page 2 the url will show http://www.whatever.com/page.php?p=2&order_by=name Then when I click on page 3 it will show http://www.whatever.com/page.php?p=2&order_by=name&p=3&order_by=name and so on and there are alot more variables so the url gets unreadable really quickly. I want to build a function that removes this to make the code more readable so I did this $file = removeCrap($this->url); function removeCrap($file) { echo 'Here'; //these are some of the fields I am removing. if (strpos($file,'&_pjax=%23pjax-container')) { $file = str_replace('&_pjax=%23pjax-container','',$file); } if (strpos($file,'&gridOrder=cust_name%20DESC%20')) { $file = str_replace('&gridOrder=cust_name%20DESC%20','',$file); } if (strpos($file,'&gridOrder=cust_name%20ASC%20')) { $file = str_replace('&gridOrder=cust_name%20ASC%20','',$file); } if (strpos($file,'p=')) { $file = str_replace('p=','',$file); } if (strpos($file,'&order=ASC')) { $file = str_replace('&order=ASC','',$file); } return $file; } I have commented out the return to test to see if that helps but my code never reaches the echo statement. If I remove the function and just place it in the same function that's building the url for the pages it works but clutters up the function. Why can't I create a separate function to make the code cleaner? Also, any suggestions on removing page numbers would help too. I can just loop through page 1 to 100 and remove them if they exist but I would rather just be able to know exactly what to remove. For example: http://www.whatever.com/page.php?p=2&order_by=name Since I don't know what page number to remove in the code because it could be page 1 or 50 I would want to know to remove p=2 without having to loop through 100 numbers just to clean up a url.
  5. Just to make sure I am doing this accurately I changed the code to this class Customer extends VerySimpleModel implements TemplateVariable { static $meta = array( 'table' => CUST_TABLE, 'pk' => array('cust_id'), 'joins' => array( 'location' => array( 'constraint' => array('cust_id' => 'loc.cust_id'), ), 'service' => array( 'constraint' => array('service_level' => 'service.id'), ), ), ); public $id; public $name; public $contact; public $fname; public $lname; public $contact_phone; public $phone_number; public $fax_number; public $location; public $domain; public $service_level; public $row; public $address; public $_location = null; public function _construct( $id=0 ) { echo 'here'; $this->id=0; if($id && ($info=$this->getInfoById($id)) ){ $this->row=$info; $this->id=$info["id"]; $this->name=$info["cust_name"]; $this->domain=$info["domain"]; $this->location=$this->getLocationInfo($id); $this->service_level=$info["service_level"]; } } } \\and I call it like this from the other page $cust = new Customer($_REQUEST['id']); If I do that it should go to the construct function correct? Because I can't get it to print 'here'.
  6. The error reporting is not turned on in the php.ini file. It was just locally in the page and by breaks the page it was solid white. Though now, it just displays no record in the grid. I just got back in so I'll try turning on errors in the ini file and that should help. Also I will change all his var code to public and read up on the new php.
  7. I have a class called Customer and I created a function called Customer with a parameter of id in order to load a customer based on whether they exist already using an id. When I add the function, it breaks the page. I turned error logging on but it's not helping. I get scores of errors mostly undefined index and this method is outdated but no fatal errors and no explanation of why adding this class breaks my page. Here is my code: class Customer extends VerySimpleModel implements TemplateVariable { static $meta = array( 'table' => CUST_TABLE, 'pk' => array('cust_id'), 'joins' => array( 'location' => array( 'constraint' => array('cust_id' => 'loc.cust_id'), ), 'service' => array( 'constraint' => array('service_level' => 'service.id'), ), ), ); var $id; var $name; var $contact; var $fname; var $lname; var $contact_phone; var $phone_number; var $fax_number; var $location; var $domain; var $service_level; var $row; var $address; var $_location = null; public function Customer( $id=0 ) { echo 'here'; $this->id=0; if($id && ($info=$this->getInfoById($id)) ){ $this->row=$info; $this->id=$info["id"]; $this->name=$info["cust_name"]; $this->domain=$info["domain"]; $this->location=$this->getLocationInfo($id); $this->service_level=$info["service_level"]; } } } //page that is loading the Grid data $custs = Customer::objects(); I think it has something to do with the way that $custs is being loaded but I can't find any good detail on what objects() even is in php so I can't really figure out exactly what that line is doing and if that's even the problem.
  8. Thanks I will try that backtrace. Haven't seen that trick yet.
  9. I figured that part out but when I name it to Customer another page doesn't work (my data grid page). It only works when the function is named Cust even though I have removed every instance of that and changed it to customer.
  10. Okay I thought I was finally starting to get the hang of php so I went through trying to clean up some code. I changed all instances of my class Cust to Customer just for clarification. That's when I ran into a weird problem. I had a page that shows a grid of customers and it was calling this function //code that calls the class $custs = Customer::objects(); //this is the class declaration class Customer extends VerySimpleModel implements TemplateVariable { static $meta = array( 'table' => CUST_TABLE, 'pk' => array('cust_id'), 'joins' => array( 'location' => array( 'constraint' => array('cust_id' => 'loc.cust_id'), ), 'service' => array( 'constraint' => array('service_level' => 'service.id'), ), ), ); var $cust_id; var $name; var $contact; var $fname; var $lname; var $contact_phone; var $phone_number; var $fax_number; var $location; var $domain; var $service_level; var $row; var $address; var $_location = null; //this is the function causing problems function Cust( $id=0 ) { $this->id=0; if($id && ($info=$this->getInfoById($id)) ){ $this->row=$info; $this->id=$info["cust_id"]; $this->cust_name=$info["cust_name"]; $this->domain=$info["domain"]; $this->location=$this->getLocationInfo($id); //$this->note=$this->getNotes($id); $this->service_level=$info["service_level"]; } } When I change that last function to Customer it breaks my grid and the grid doesn't load. However, nothing in my code is now calling that function as doing a search on my entire project in eclipse gives me no results. If I leave it as Cust my grid works but when I click on a customer to edit that doesn't work unless the function is named Customer. What happened and why is this code still calling a function by his old name?
  11. I think I figured it out. Because it's null it seems to be throwing an error though it didn't do that in the old code. Not sure why the change but when I did this it didn't throw an error. if (isset($this->cust_id)) { return $this->cust_id; } return 0; Php seems to be really weird about tags. For instance the old coder did a lot of "<? ?>" tags and if I change one to "<?php ?>" it freaks out and breaks the whole page. And, the reason I have to change some is because the page isn't working properly even though it did in the old website.
  12. Okay so I changed my code to the following page 1: if(!isset($_POST['add'])){ $customer = new Cust(); if($customer && $thisstaff->isAdmin()) { if( $customer->update($_POST,$errors,0)){ $msg='Customer record created successfully'; $_POST=null; }elseif(!$errors['err']) $errors['err']='Error creating customer record'; } } page 2 function update($vars, &$errors, $myID=null, $location_number=0, $mass=true){ return $this->save($this->getId(), $vars, $errors, $location_number, $mass )?true:false; } function getId() { return $this->cust_id; } And it breaks. I get a blank page. However, if I do the following it works... function update($vars, &$errors, $myID=null, $location_number=0, $mass=true){ return $this->save($myID, $vars, $errors, $location_number, $mass )?true:false; } This is why I changed it to begin with. For some reason it doesn't like that "$this->getId()" function. Thanks for the static/non static tip.
  13. No it was [ / ] without the spaces. That's what I was told sorry maybe this will work better. if(!isset($_POST['add'])){ $customer = new Customer(); if($customer && $thisuser->canEditCustomer()) if( $customer->update($_POST,$errors)){ $msg='Customer record created successfully'; $_POST=null; }elseif(!$errors['err']) $errors['err']='Error creating customer record'; }
  14. I meant to format that better before I sent but my keyboard seems to have a mind of it's own at the moment... if($thisstaff->isAdmin()) if( Cust::update($_POST,$errors,0)){ $msg='Customer record created successfully'; $_POST=null; }elseif(!$errors['err']) $errors['err']='Error creating customer record'; However, I can echo out statements in the update function. I can even make it to the save function so I wouldn't think the initial call would be the problem.
×
×
  • 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.