public function loadArrayKeyValueSearch($searchTermArray) { $returnvalue = array(); $and = ''; $wherebit = 'WHERE '; foreach ($searchTermArray as $fieldname => $searchTerm) { if ($this->hasField($fieldname)) { $operator = '='; // change to a like search if a wildcard character is present if (!(strpos($searchTerm, '%') === false)) { $operator = 'like'; } if (!(strpos($searchTerm, '_') === false)) { $operator = 'like'; } if ($searchTerm == '[NULL]') { $wherebit .= "{$and} ({$fieldname} is null or {$fieldname}='') "; } else { $wherebit .= "{$and} {$fieldname} {$operator} ? "; $types = $types . $this->MySQLiFieldType($fieldname); } $and = ' and '; } } $sql = "SELECT agentlinksid FROM agentlinks {$wherebit}"; if ($wherebit == '') { $this->error = 'Error: No search terms provided'; } else { $statement = $this->conn->prepare($sql); $vars = array(); $vars[] = $types; $i = 0; foreach ($searchTermArray as $value) { $varname = 'bind' . $i; // create a variable name ${$varname} = $value; // using that variable name store the value $vars[] =& ${$varname}; // add a reference to the variable to the array $i++; } //$vars[] contains $types followed by references to variables holding each value in $searchTermArray. call_user_func_array(array($statement, 'bind_param'), $vars); //$statement->bind_param($types,$names); $statement->execute(); $statement->bind_result($id); $ids = array(); while ($statement->fetch()) { $ids[] = $id; } // double loop to allow all data to be retrieved before preparing a new statement. $statement->close(); for ($i = 0; $i < count($ids); $i++) { $obj = new agentlinks(); $obj->load($ids[$i]); $returnvalue[] = $obj; $result = true; } if ($result === false) { $this->error = mysqli_error($this->conn); } } return $returnvalue; }
function loadAgentLinks() { $al = null; $alid = preg_replace('[^0-9]', '', array_key_exists("agentlinksid", $_REQUEST) ? $_REQUEST["agentlinksid"] : ""); if (strlen($alid) > 0) { $al = new agentlinks(); $al->load($alid); } else { throw new Exception("No agent links record specified."); } return $al; }