當前位置: 首頁>>代碼示例>>PHP>>正文


PHP wpdb::get_results方法代碼示例

本文整理匯總了PHP中wpdb::get_results方法的典型用法代碼示例。如果您正苦於以下問題:PHP wpdb::get_results方法的具體用法?PHP wpdb::get_results怎麽用?PHP wpdb::get_results使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wpdb的用法示例。


在下文中一共展示了wpdb::get_results方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setTable

 /**
  * Bind model to database table
  * @param string $tableName
  * @return PMXI_Model
  */
 public function setTable($tableName)
 {
     if (!is_null($this->table)) {
         throw new Exception('Table name cannot be changed once being set.');
     }
     $this->table = $tableName;
     if (!isset(self::$meta_cache[$this->table])) {
         $tableMeta = $this->wpdb->get_results("SHOW COLUMNS FROM {$this->table}", ARRAY_A);
         $primary = array();
         $auto_increment = false;
         foreach ($tableMeta as $colMeta) {
             if ('PRI' == $colMeta['Key']) {
                 $primary[] = $colMeta['Field'];
             }
             if ('auto_increment' == $colMeta['Extra']) {
                 $auto_increment = true;
                 break;
                 // no point to iterate futher since auto_increment means corresponding primary key is simple
             }
         }
         self::$meta_cache[$this->table] = array('primary' => $primary, 'auto_increment' => $auto_increment);
     }
     $this->primary = self::$meta_cache[$this->table]['primary'];
     $this->auto_increment = self::$meta_cache[$this->table]['auto_increment'];
     return $this;
 }
開發者ID:thabofletcher,項目名稱:tc-site,代碼行數:31,代碼來源:model.php

示例2: fetchAll

 /**
  * {@inheritdoc}
  */
 public function fetchAll($sql)
 {
     $sql = $this->_prepareSql($sql);
     $result = $this->_db->get_results($sql, ARRAY_A);
     $this->_checkError();
     return $result;
 }
開發者ID:JBZoo,項目名稱:CrossCMS,代碼行數:10,代碼來源:Database.php

示例3: load

 public function load($staff_id)
 {
     $data = $this->wpdb->get_results('
         SELECT c.name AS category_name, s.*
         FROM ' . AB_Category::getTableName() . ' c
         INNER JOIN ' . AB_Service::getTableName() . ' s ON c.id = s.category_id
     ', ARRAY_A);
     if (!$data) {
         $data = array();
     }
     $this->uncategorized_services = AB_Service::query('s')->where('s.category_id', null)->fetchArray();
     $staff_services = AB_StaffService::query('ss')->select('ss.service_id, ss.price, ss.capacity')->where('ss.staff_id', $staff_id)->fetchArray();
     if ($staff_services) {
         foreach ($staff_services as $staff_service) {
             $this->selected[$staff_service['service_id']] = array('price' => $staff_service['price'], 'capacity' => $staff_service['capacity']);
         }
     }
     foreach ($data as $row) {
         if (!isset($this->collection[$row['category_id']])) {
             $abCategory = new AB_Category();
             $abCategory->set('id', $row['category_id']);
             $abCategory->set('name', $row['category_name']);
             $this->collection[$row['category_id']] = $abCategory;
         }
         unset($row['category_name']);
         $abService = new AB_Service($row);
         $this->category_services[$row['category_id']][] = $abService->get('id');
         $this->collection[$row['category_id']]->addService($abService);
     }
 }
開發者ID:patrickcurl,項目名稱:monks,代碼行數:30,代碼來源:AB_StaffServicesForm.php

示例4: getResults

 public function getResults($query, $parameters = array())
 {
     if (!empty($parameters)) {
         $query = str_replace('?', '%s', $query);
         $query = $this->wpdb->prepare($query, $parameters);
     }
     return $this->wpdb->get_results($query, ARRAY_A);
 }
開發者ID:nikibrown,項目名稱:2014-Nerd-presentation,代碼行數:8,代碼來源:WpDatabase.php

示例5: fetchAll

 /**
  * Fetch all results for the supplied SQL statement.
  *
  * @param string|\Dewdrop\Db\Select $sql
  * @param array $bind
  * @param string $fetchMode
  * @return array
  */
 public function fetchAll($sql, $bind = array(), $fetchMode = null)
 {
     if (null === $fetchMode) {
         $fetchMode = ARRAY_A;
     }
     $sql = $this->adapter->prepare($sql, $bind);
     $rs = $this->execWpdb($this->wpdb->get_results($sql, $fetchMode));
     return $rs;
 }
開發者ID:bravadomizzou,項目名稱:dewdrop,代碼行數:17,代碼來源:Wpdb.php

示例6: translations

 /**
  * @return WPML_TM_ICL_Translations[]
  */
 public function translations()
 {
     if ((bool) $this->related === false) {
         $translation_ids = $this->wpdb->get_results("SELECT translation_id, language_code\n\t\t\t FROM {$this->wpdb->prefix}{$this->table}\n\t\t\t WHERE trid = " . $this->trid());
         foreach ($translation_ids as $row) {
             $this->related[$row->language_code] = $this->tm_records->icl_translations_by_translation_id($row->translation_id);
         }
     }
     return $this->related;
 }
開發者ID:agiper,項目名稱:wordpress,代碼行數:13,代碼來源:class-wpml-tm-icl-translations.php

示例7: retrieve

 /**
  * @param string $query
  * @param array $args
  * @param int $elements_num
  *
  * @return array
  */
 public function retrieve($query, $args, $elements_num)
 {
     $result = array();
     $offset = 0;
     while ($offset < $elements_num) {
         $new_query = $query . sprintf(' LIMIT %d OFFSET %s', $this->chunk_size, $offset);
         $new_query = $this->wpdb->prepare($new_query, $args);
         $rowset = $this->wpdb->get_results($new_query, ARRAY_A);
         if (is_array($rowset) && count($rowset)) {
             $result = array_merge($result, $rowset);
         }
         $offset += $this->chunk_size;
     }
     return $result;
 }
開發者ID:studiopengpeng,項目名稱:ASCOMETAL,代碼行數:22,代碼來源:class-wpml-st-db-chunk-retrieve.php

示例8: array

 function get_active_subscriptions()
 {
     $where = array();
     $orderby = array();
     $where[] = "sub_active = 1";
     $orderby[] = 'id ASC';
     $sql = 'SELECT * FROM ' . MEMBERSHIP_TABLE_SUBSCRIPTIONS;
     if (!empty($where)) {
         $sql .= " WHERE " . implode(' AND ', $where);
     }
     if (!empty($orderby)) {
         $sql .= " ORDER BY " . implode(', ', $orderby);
     }
     return $this->db->get_results($sql);
 }
開發者ID:vilmark,項目名稱:vilmark_main,代碼行數:15,代碼來源:class.communication.php

示例9: get_forms

 /**
  * Gets all the rows in a particular range. Used by the list table class for fetching forms on a particular page.
  *
  * @param int $curr_page Current page of the list table.
  * @param int $per_page Number of items to fetch.
  * @return array A numerically indexed array of associative arrays, using column names as keys.
  **/
 public function get_forms($curr_page, $per_page, $post_type = false)
 {
     $start = ($curr_page - 1) * $per_page;
     $where = $post_type ? "post_type = '{$post_type}'" : 1;
     $query = "SELECT * FROM {$this->table_name} WHERE {$where} ORDER BY id DESC LIMIT {$start}, {$per_page}";
     return $this->db->get_results($query, ARRAY_A);
 }
開發者ID:poweronio,項目名稱:mbsite,代碼行數:14,代碼來源:class-wpfepp-db-table.php

示例10: fleet_roster_handler

function fleet_roster_handler($atts)
{
    extract(shortcode_atts(array('prefix' => ''), $atts));
    $response = '';
    if ($prefix) {
        $novadb = new wpdb('<username>', '<user password>', '<database>', '<server>');
        if ($novadb->show_errors()) {
            return $novadb->show_errors();
        }
        $response = '';
        $query = "SELECT pos_name, pos_open from " . $prefix . "_positions_sto where pos_open > 0 order by pos_dept, pos_order;";
        $rows = $novadb->get_results($query);
        if (!$novadb->num_rows) {
            return "No Positions available at this time.";
        }
        $i = 0;
        foreach ($rows as $row) {
            $response .= $row->pos_name;
            if ($row->pos_open > 1) {
                $response .= ' (' . $row->pos_open . ' open)';
            }
            $i++;
            if ($i < $novadb->num_rows) {
                $response .= ' - ';
            }
        }
        return $response;
    }
    return 'Please enter a Command Prefix Code.';
}
開發者ID:arcee123,項目名稱:WP_Plugin_NOVA,代碼行數:30,代碼來源:NOVA_Openings.php

示例11: download

 /**
  * Log download
  *
  * If you are viewing the right admin page and you use the right GET
  * parameters, this will send the CSV version of the log.
  *
  * @return void
  */
 public function download()
 {
     if (!$this->isDownload()) {
         return;
     }
     // Generate a file name and query based on the group parameters
     $name = $this->downloadName();
     $where = $this->downloadWhere();
     // Add CSV headers
     header('Content-Type: text/csv');
     header('Content-Disposition: attachment; filename="' . $name . '.csv"');
     // Extract the log data from the database and convert it to CSV format
     $results = $this->database->get_results("\n            SELECT *\n            FROM {$this->table}\n            WHERE {$where}\n        ");
     // Print CSV output
     $csv = fopen('php://output', 'w');
     // Extract headings from a database row and add them to the CSV
     fputcsv($csv, $this->headings(end($results)));
     // Extract values from each result and add them to the CSV
     foreach ($results as $result) {
         fputcsv($csv, $this->values($result));
     }
     // Finish writing CSV
     fclose($csv);
     // Prevent the rest of the page appearing in the CSV file
     exit;
 }
開發者ID:castlegateit,項目名稱:cgit-wp-postman,代碼行數:34,代碼來源:Lumberjack.php

示例12: query

 /**
  * Execute the query, with the current variables.
  *
  * @since 3.1.0
  */
 public function query()
 {
     $qv =& $this->query_vars;
     $this->request = "SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}";
     if (is_array($qv['fields']) || 'all' == $qv['fields']) {
         $this->results = $this->db->get_results($this->request);
     } else {
         $this->results = $this->db->get_col($this->request);
     }
     /**
      * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance.
      *
      * @since 3.2.0
      *
      * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query.
      */
     if (isset($qv['count_total']) && $qv['count_total']) {
         $this->total_users = $this->db->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()'));
     }
     if (!$this->results) {
         return;
     }
     if ('all_with_meta' == $qv['fields']) {
         cache_users($this->results);
         $r = array();
         foreach ($this->results as $userid) {
             $r[$userid] = new WP_User($userid, '', $qv['blog_id']);
         }
         $this->results = $r;
     } elseif ('all' == $qv['fields']) {
         foreach ($this->results as $key => $user) {
             $this->results[$key] = new WP_User($user, '', $qv['blog_id']);
         }
     }
 }
開發者ID:atimmer,項目名稱:wordpress-develop-mirror,代碼行數:40,代碼來源:class-wp-user-query.php

示例13: get_existing_translation_ids

 /**
  * @param $source_site_id
  * @param $target_site_id
  * @param $source_content_id
  * @param $target_content_id
  * @param $type
  * @return mixed
  */
 private function get_existing_translation_ids($source_site_id, $target_site_id, $source_content_id, $target_content_id, $type)
 {
     $sql = "\n\t\t\tSELECT DISTINCT `ml_source_blogid`, `ml_source_elementid`\n\t\t\tFROM {$this->link_table}\n\t\t\tWHERE (\n\t\t\t\t   ( `ml_blogid` = %d AND `ml_elementid` = %d )\n\t\t\t\tOR ( `ml_blogid` = %d AND `ml_elementid` = %d )\n\t\t\t\t)\n\t\t\t\tAND `ml_type` = %s";
     $query = $this->wpdb->prepare($sql, $source_site_id, $source_content_id, $target_site_id, $target_content_id, $type);
     $result = $this->wpdb->get_results($query, ARRAY_A);
     return $result;
 }
開發者ID:ycms,項目名稱:framework,代碼行數:15,代碼來源:Mlp_Content_Relations.php

示例14: getTopFailedLogins

    /**
     * @param int $limit
     * @return mixed
     */
    public function getTopFailedLogins($limit = 10)
    {
        $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 7 day))';
        switch (wfConfig::get('email_summary_interval', 'weekly')) {
            case 'biweekly':
                $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 14 day))';
                break;
            case 'monthly':
                $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 1 month))';
                break;
        }
        $results = $this->db->get_results($this->db->prepare(<<<SQL
SELECT *,
sum(fail) as fail_count,
max(userID) as is_valid_user
FROM {$this->db->base_prefix}wfLogins
WHERE fail = 1
AND ctime > {$interval}
GROUP BY username
ORDER BY fail_count DESC
LIMIT %d
SQL
, $limit));
        return $results;
    }
開發者ID:rinodung,項目名稱:myfreetheme,代碼行數:29,代碼來源:wfActivityReport.php

示例15: tgp_get_products

function tgp_get_products()
{
    // Connect to the database
    $db = new wpdb(get_option('db_user'), get_option('db_pass'), get_option('db_name'), get_option('db_host'));
    // Get values
    $store_url = get_option('store_url');
    $img_folder = get_option('img_folder');
    $num_products = get_option('num_products');
    // Get Products
    $products = $db->get_results("SELECT * FROM products LIMIT " . $num_products);
    // Build Output
    $output = '';
    if ($products) {
        foreach ($products as $product) {
            $output .= '<div class="tgp_product">';
            $output .= '<h3>' . $product->title . '</h3>';
            $output .= '<img src="' . $store_url . '/' . $img_folder . '/' . $product->image . '" alt="' . $product->title . '">';
            $output .= '<div class="price">' . $product->price . '</div>';
            $output .= '<div class="desc">' . wp_trim_words($product->description, 10) . '</div>';
            $output .= '<a href="' . $store_url . 'products/details/' . $product->id . '">Buy Now</a>';
        }
    } else {
        $output .= 'No products to list';
    }
    return $output;
}
開發者ID:alt3red,項目名稱:thegamingplace,代碼行數:26,代碼來源:thegamingplace.php


注:本文中的wpdb::get_results方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。