Jump to content

NotSureILikePHP

Members
  • Posts

    40
  • Joined

  • Last visited

Everything posted by NotSureILikePHP

  1. That didn't work. It's being called from a different page so I'll include all the code. customers.inc.php $locations = Cust::getLocations($customerID); echo 'locations = '.$locations[0]['location_id']; [/] class.customer.php [code] function getLocations($custID) { $locs = array(); $sql='SELECT DISTINCT l.location_id, l.site_name FROM ' //l.location_id, l.site_name, CONCAT(l.fname, " ", l.lname) AS contactName, email, ' //.'l.phone_number, l.fax_number, c.cust_id, l.address1, l.address2, l.city, ' //.'l.state, l.zip_code, l.contact_number FROM ' .CUST_TABLE.' c ' .' LEFT JOIN '.CUST_LOCATION_TABLE.' l ON (l.cust_id=c.cust_id) ' //.' INNER JOIN '.DEPT_TABLE.' d ON (LOCATE(CONCAT("/", s.dept_id, "/"), d.path) OR d.manager_id=s.staff_id OR LOCATE(CONCAT("/", g.dept_id, "/"), d.path)) ' .' WHERE c.cust_id='.$custID; //.db_input($this->getId()); if (($res=db_query($sql)) && db_num_rows($res)) { while(list($loc)=db_fetch_row($res)) { $columns = array ( 'locID' => $loc['location_id'], 'locName' => $loc['site_name'], ); $locs[] = $columns; } } return $locs; } [/] result is locations = I commented out a lot of that select just to limit it to two columns for now.
  2. It is an empty array I'll try that
  3. I'm trying to add multiple columns to an array. To simplify I'll just say id and name for now. How do I add and call that in the code. I am an asp developer, though it's been a while, so in asp it's something like array[0],["columnName'] Though in php that dot means to concat. Here's my code. $int = 0; if (($res=db_query('SELECT id, name FROM location')) && db_num_rows($res)) { while(list($loc)=db_fetch_row($res)) { $columns = array ( 'locID' => $loc['location_id'], 'locName' => $loc['site_name'], ); array_push($locs[$int], $columns); $int++; } } [/] I'm not sure if that's working or not because I don't know how to get values from the index of the array in php. Most of the code I google seems like an array can only store one value per index.
  4. I do have Eclipse installed but I can't figure out how to chase the rabbit. I can get it to debug on certain pages but I have spent 30 minutes hitting step into and not gotten to the spot that I want because the code is so convoluted. It starts debugging right away and I have told it not to in the settings and when I hit play the first time it never hits another breakpoint. Is there a better debugger than Eclipse and XDebug or am I just doing something wrong?
  5. I NEVER get a good answer here so I stopped posting and just post on PHP Phreaks but this is way too confusing so I have to try here. I can NOT for the life of me figure out what is going on with this code. It's so horribly coded and I'm new to php so it's like trying to learn Mandarin from a special needs kid. I created a class called Customers by mimicking the staff class. I can populate my grid with all the customers but when I try to search by a specific customer I have to know the full name WITH all the right capitalization. I'm trying to track down where the query is called but these coders don't use stored procedures they dynamically build them and it's one of the most complicated things I've ever seen. Here's the line of code I'm trying to trace, I think.... if ($filters) { $custs->filter($filters); } [/] Now I can find this function and when I echo what it returns it returns the querystring WHERE A1.`cust_name` = 'test' which is exactly what I am looking for. However, I can't trace it any further than that. This is the code in that function [code] foreach (func_get_args() as $Q) { $this->constraints[] = $Q instanceof Q ? $Q : new Q($Q); } [/] The Query looks like SELECT A1.`cust_name` FROM `ost_customer` A1 WHERE A1.`cust_name` = 'test' I have spent HOURS searching this code for A1 (returns thousands of rows), SELECT (which returns even more rows around 4 thousand), CUST_TABLE which is the variable my customer table name is stored and I have found NOTHING. Can anyone help me find where this code is located so I can change it? I really wish they just used stored procedures. It would make this whole project so much more readable. I would also like to know how to add % to a textbox. For example, I have a textbox so that the user can type "Test" and it should return 1 customer in the database named "Testy Corporate" but it doesn't unless you type the whole name. I would like to add % to the beginning and end like "%test%". However, when you hit submit it posts back and runs the query. Now, I'm assuming if I ever find the place where the sql statement is called I should be able to change that but is there a way that when you hit submit it automatically appends that to the text?
  6. I'm assuming this is a function in php, though still not entirely sure what arrows are in coding. Here's the line: if ($filters) $custs->filter($filters); [/] $Custs is an object of type customer. Other languages don't have -> but if I'm not mistaken it's a function. I'm searching the entire project for "function filter" and I get 3 results but none of them are the right location. Only one of them accepts parameters and I know it's not the right code because it never reaches that function. Can someone tell me exactly what I should be looking for? I'm trying to search for a specific customer. However it's searching on customer name = "whatever" rather than customer name like "whatever" and I can't seem to find where it's defined in the code.
  7. Thanks, I for some reason was thinking because I didn't need to display it I didn't need to echo it.
  8. I might have figured this out by the time I get a response but then again maybe not. I am trying to dynamically add hyperlinks to a grid that I am populating. Here is the code: <?php if ($count) { $ids= ($errors && is_array($_POST['ids'])) ? $_POST['ids'] : null; foreach ($custs as $cust) { $id = $cust->getId(); $name = $cust->getName(); ?> <tr id="<?php echo $id; ?>"> <td width=7px> <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $id; ?>" <?php echo $sel? 'checked="checked"' : ''; ?> <?php echo $default? 'disabled="disabled"' : ''; ?> > </td> <td><a href="customers.php?t=customer&id=<?php $id ?>"><?php echo $name; ?></a></td> </tr> <?php } //end of foreach. } ?> [/] It builds the link customers.php?t=customer&id= However, when I echo out the $id it displays. I'm sure there's something simple I'm not doing here but not sure what it is.
  9. So there are multiple errors but the first one it give me is undefined index here is line 15: && $sortOptions[strtolower($_REQUEST['sort'])]) ? strtolower($_REQUEST['sort']) : 'name'; ] the array is set before then on line 7 and it's as follows: [ code $sortOptions=array( 'name' => 'cust_name','contact' => 'contact','phone'=> 'phone_number','address'=> 'address'); ] I'm not sure why it's throwing that error.
  10. That is extremely helpful! And sorry about the tags. I wasn't sure how to tag around html and php at the same time and still make the code readable for people. I figured that might get confusing.
  11. I am trying to call something simple like Customer->getID() but it causes things on the page to dissappear. When I try to echo out the ID I get nothing. The class is attached in a file. I am trying to call it with the following code: $custs = Cust::getCustomers(); $count = count($custs); <?php if ($count) { //$custs = Cust::getCustomers(); $ids= ($errors && is_array($_POST['ids'])) ? $_POST['ids'] : null; foreach ($custs as $cust) { $id = $cust->id(); $name = $cust['cust_name']; ?> <tr id="<?php echo $id; ?>"> <td width=7px> <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $id; ?>" <?php echo $sel? 'checked="checked"' : ''; ?> <?php echo $default? 'disabled="disabled"' : ''; ?> > </td> <td><?php echo $name; ?></td> </tr> <?php } //end of foreach. } ?> I know the count is 229 because if I add an echo statement after assigning the count I get 229. I have tried getting the properties with ->id() ->getID() and $cust['id']
  12. That looks like it's the problem. I was trying to use their code but it's so convoluded that I can't even figure out where I should put the query so I hard coded it into the get customers. However, I was still using their customer object that wasn't defined in my code. I got it working now. Thank you! I'm a .Net programmer and everything is much more simplistic with software that you actually paid for.
  13. Yeah this is for OSTickets which is an open source ticketing system. They use a ton of code! I'm still new to PHP so trying to sort through all of it is rather intense. I believe this is the correct function for $__db->query(). I am still getting used to not always being able to right click and go to the line. I'm using eclipse for debugging but it really doesn't work most of the time. public function query($name, $type = 'A', $class = 'IN') { // // make sure we have some name servers set // $this->checkServers(Net_DNS2::RESOLV_CONF); // // we dont' support incremental zone tranfers; so if it's requested, a full // zone transfer can be returned // if ($type == 'IXFR') { $type = 'AXFR'; } // // if the name *looks* too short, then append the domain from the config // if ( (strpos($name, '.') === false) && ($type != 'PTR') ) { $name .= '.' . strtolower($this->domain); } // // create a new packet based on the input // $packet = new Net_DNS2_Packet_Request($name, $type, $class); // // check for an authentication method; either TSIG or SIG // if ( ($this->auth_signature instanceof Net_DNS2_RR_TSIG) || ($this->auth_signature instanceof Net_DNS2_RR_SIG) ) { $packet->additional[] = $this->auth_signature; $packet->header->arcount = count($packet->additional); } // // check for the DNSSEC flag, and if it's true, then add an OPT // RR to the additional section, and set the DO flag to 1. // if ($this->dnssec == true) { // // create a new OPT RR // $opt = new Net_DNS2_RR_OPT(); // // set the DO flag, and the other values // $opt->do = 1; $opt->class = $this->dnssec_payload_size; // // add the RR to the additional section. // $packet->additional[] = $opt; $packet->header->arcount = count($packet->additional); } // // set the DNSSEC AD or CD bits // if ($this->dnssec_ad_flag == true) { $packet->header->ad = 1; } if ($this->dnssec_cd_flag == true) { $packet->header->cd = 1; } // // if caching is turned on, then check then hash the question, and // do a cache lookup. // // don't use the cache for zone transfers // $packet_hash = ''; if ( ($this->use_cache == true) && ($this->cacheable($type) == true) ) { // // open the cache // $this->cache->open( $this->cache_file, $this->cache_size, $this->cache_serializer ); // // build the key and check for it in the cache. // $packet_hash = md5( $packet->question[0]->qname . '|' . $packet->question[0]->qtype ); if ($this->cache->has($packet_hash)) { return $this->cache->get($packet_hash); } } // // set the RD (recursion desired) bit to 1 / 0 depending on the config // setting. // if ($this->recurse == false) { $packet->header->rd = 0; } else { $packet->header->rd = 1; } // // send the packet and get back the response // // *always* use TCP for zone transfers- does this cause any problems? // $response = $this->sendPacket( $packet, ($type == 'AXFR') ? true : $this->use_tcp ); // // if strict mode is enabled, then make sure that the name that was // looked up is *actually* in the response object. // // only do this is strict_query_mode is turned on, AND we've received // some answers; no point doing any else if there were no answers. // if ( ($this->strict_query_mode == true) && ($response->header->ancount > 0) ) { $found = false; // // look for the requested name/type/class // foreach ($response->answer as $index => $object) { if ( (strcasecmp($object->name, $name) == 0) && ($object->type == $type) && ($object->class == $class) ) { $found = true; break; } } // // if it's not found, then unset the answer section; it's not correct to // throw an exception here; if the hostname didn't exist, then // sendPacket() would have already thrown an NXDOMAIN error- so the host // *exists*, but just not the request type/class. // // the correct response in this case, is an empty answer section; the // authority section may still have usual information, like a SOA record. // if ($found == false) { $response->answer = array(); $response->header->ancount = 0; } } // // cache the response object // if ( ($this->use_cache == true) && ($this->cacheable($type) == true) ) { $this->cache->put($packet_hash, $response); } return $response; }
  14. That actually helps a lot and explains why I couldn't find much help on db_query. Here is the function function db_query($query, $logError=true, $buffered=true) { global $ost, $__db; if ($__db->unbuffered_result) { $__db->unbuffered_result->free(); $__db->unbuffered_result = false; } $tries = 3; do { $res = $__db->query($query, $buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); // Retry the query due to deadlock error (#1213) // TODO: Consider retry on #1205 (lock wait timeout exceeded) // TODO: Log warning } while (!$res && --$tries && $__db->errno == 1213); if(!$res && $logError && $ost) { //error reporting // Allow $logError() callback to determine if logging is necessary if (is_callable($logError) && !($logError($__db->errno))) return $res; $msg='['.$query.']'."\n\n".db_error(); $ost->logDBError('DB Error #'.db_errno(), $msg); //echo $msg; #uncomment during debuging or dev. } if (is_object($res) && !$buffered) $__db->unbuffered_result = $res; return $res; }
  15. There are 228 results in the database but it only returns the top result. When I echo the $sql statement being called and paste that into mysql I get all 228 records. Here's the example. $sql='SELECT cust.id, cust.cust_name, cust.doman FROM cust_table'; return db_query($sql); This is returned to another included page. However, I have taken that query and pasted it into sql and get all 228 results. If I do this... $sql='SELECT cust.id, cust.cust_name, cust.doman FROM cust_table'; echo count(db_query($sql)); return db_query($sql); I get 1 result. I'm stumped...
×
×
  • 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.