Public paste
Undefined
By: fruffl | Date: May 29 2010 15:29 | Format: None | Expires: never | Size: 1.17 KB | Hits: 757

  1. <?PHP
  2.                 public function simple_multi_search($tablename, array $statemats, $options = array('limit' => 1))
  3.                 {
  4.                         $this->db_connection_test();
  5.                        
  6.                         $conditions = array();
  7.                        
  8.                        
  9.                         foreach($statemats as $fieldname => $value)
  10.                         {
  11.                                 switch(substr($value, 0, 1)):
  12.                                         case '>':
  13.                                                 $conditions[] = $fieldname." > '".substr($value, 1)."'";
  14.                                                 break;
  15.                                         case '<':
  16.                                                 $conditions[] = $fieldname." < '".substr($value, 1)."'";
  17.                                                 break;
  18.                                         default:
  19.                                                 switch(substr($value, 0, 2)):
  20.                                                         case '>=':
  21.                                                                 $conditions[] = $fieldname." >= '".$value."'";
  22.                                                                 break;
  23.                                                         case '<=':
  24.                                                                 $conditions[] = $fieldname." <= '".$value."'";
  25.                                                                 break;
  26.                                                         default:
  27.                                                                 $conditions[] = $fieldname." = '".$value."'";
  28.                                                 endswitch;
  29.                                 endswitch;
  30.                         }
  31.                                
  32.                                
  33.  
  34.                         $query = $this->DB->simple_select($tablename, "*", implode(' AND ', $conditions), $options);
  35.                        
  36.                        
  37.                         if($query)
  38.                         {
  39.                                 $cache = array();
  40.                                
  41.                                 while($res = $this->db_fetch_array($query))
  42.                                 {      
  43.                                         $cache[] = $res;
  44.                                 }
  45.                                
  46.                                 if(count($cache) > 0)
  47.                                         return $cache;
  48.                         }
  49.                        
  50.                         return FALSE;
  51.                 }