function ExecuteRandom($zf_sql, $zf_limit = 0, $zf_cache = false, $zf_cachetime = 0)
 {
     //    if ($zf_limit) {
     //      $zf_sql = $zf_sql . ' LIMIT ' . $zf_limit;
     //    }
     //echo $zf_sql . '<br />';
     $time_start = explode(' ', microtime());
     $obj = new queryFactoryResult();
     $obj->result = array();
     if (!$this->db_connected) {
         $this->set_error('0', DB_ERROR_NOT_CONNECTED);
     }
     $zp_db_resource = @pg_query($this->link, $zf_sql);
     if (!$zp_db_resource) {
         $this->set_error(pg_last_error());
     }
     $obj->resource = $zp_db_resource;
     $obj->cursor = 0;
     $obj->Limit = $zf_limit;
     if ($obj->RecordCount() > 0) {
         $obj->EOF = false;
         $zp_Start_row = 0;
         if ($zf_limit) {
             $zp_start_row = zen_rand(0, $obj->RecordCount() - $zf_limit);
         }
         $obj->Move($zp_start_row);
         $obj->Limit = $zf_limit;
         $zp_ii = 0;
         while (!$obj->EOF) {
             $zp_result_array = @pg_fetch_array($zp_db_resource, NULL, PGSQL_ASSOC);
             if ($zp_ii == $zf_limit) {
                 $obj->EOF = true;
             }
             if ($zp_result_array) {
                 while (list($key, $value) = each($zp_result_array)) {
                     if (!ereg('^[0-9]', $key)) {
                         //              echo $key . '=' . $value . '<br />';
                         $obj->result[$zp_ii][$key] = $value;
                     }
                 }
             } else {
                 $obj->Limit = $zp_ii;
                 $obj->EOF = true;
             }
             $zp_ii++;
         }
         $obj->result_random = array_rand($obj->result, sizeof($obj->result));
         //      echo sizeof($obj->result) . " result array ";
         //      print_r($obj->result);
         //      echo '<br /><br />';
         //      echo 'random array ';
         //      print_r($obj);
         if (is_array($obj->result_random)) {
             $zp_ptr = $obj->result_random[$obj->cursor];
         } else {
             $zp_ptr = $obj->result_random;
         }
         while (list($key, $value) = each($obj->result[$zp_ptr])) {
             if (!ereg('^[0-9]', $key)) {
                 $obj->fields[$key] = $value;
             }
         }
         $obj->EOF = false;
     } else {
         $obj->EOF = true;
     }
     $time_end = explode(' ', microtime());
     $query_time = $time_end[1] + $time_end[0] - $time_start[1] - $time_start[0];
     $this->total_query_time += $query_time;
     $this->count_queries++;
     return $obj;
 }
 function ExecuteRandomMulti($zf_sql, $zf_limit = 0, $zf_cache = false, $zf_cachetime = 0)
 {
     $this->zf_sql = $zf_sql;
     $time_start = explode(' ', microtime());
     $obj = new queryFactoryResult();
     $obj->result = array();
     if (!$this->db_connected) {
         $this->set_error('0', DB_ERROR_NOT_CONNECTED);
     }
     $zp_db_resource = @mysql_query($zf_sql, $this->link);
     if (!$zp_db_resource) {
         $this->set_error(mysql_errno(), mysql_error());
     }
     $obj->resource = $zp_db_resource;
     $obj->cursor = 0;
     $obj->Limit = $zf_limit;
     if ($obj->RecordCount() > 0 && $zf_limit > 0) {
         $obj->EOF = false;
         $zp_Start_row = 0;
         if ($zf_limit) {
             $zp_start_row = zen_rand(0, $obj->RecordCount() - $zf_limit);
         }
         $obj->Move($zp_start_row);
         $obj->Limit = $zf_limit;
         $zp_ii = 0;
         while (!$obj->EOF) {
             $zp_result_array = @mysql_fetch_array($zp_db_resource);
             if ($zp_ii == $zf_limit) {
                 $obj->EOF = true;
             }
             if ($zp_result_array) {
                 while (list($key, $value) = each($zp_result_array)) {
                     $obj->result[$zp_ii][$key] = $value;
                 }
             } else {
                 $obj->Limit = $zp_ii;
                 $obj->EOF = true;
             }
             $zp_ii++;
         }
         $obj->result_random = array_rand($obj->result, sizeof($obj->result));
         if (is_array($obj->result_random)) {
             $zp_ptr = $obj->result_random[$obj->cursor];
         } else {
             $zp_ptr = $obj->result_random;
         }
         while (list($key, $value) = each($obj->result[$zp_ptr])) {
             if (!ereg('^[0-9]', $key)) {
                 $obj->fields[$key] = $value;
             }
         }
         $obj->EOF = false;
     } else {
         $obj->EOF = true;
     }
     $time_end = explode(' ', microtime());
     $query_time = $time_end[1] + $time_end[0] - $time_start[1] - $time_start[0];
     $this->total_query_time += $query_time;
     $this->count_queries++;
     return $obj;
 }