db::field PHP Method

field() static public method

Returns a single field value from a table
static public field ( string $table, string $field, mixed $where = null, string $order = null ) : mixed
$table string The table name
$field string The name of the field
$where mixed Either a key/value array as AND connected where clause or a simple MySQL where clause string
$order string Order clause without the order keyword. ie: "added desc"
return mixed
    static function field($table, $field, $where = null, $order = null)
    {
        $result = self::row($table, $field, $where, $order);
        return a::get($result, $field);
    }

Usage Example

Example #1
0
 private static function message_model($category, $page = 1, $page_size = 15)
 {
     //处理查询条件
     $condition = null;
     $category_list = array('all' => null, 'unread' => 0, 'read' => 1);
     if (isset($category_list[$category]) && $category_list[$category] !== null) {
         $condition .= 'is_view=' . $category_list[$category];
     }
     //构造SQL语句
     $option['select'] = 'id,is_view,pub_time,user_name,tel,phone,email,message';
     $option['from'] = parent::table;
     $option['where'] = $condition;
     $option['order'] = 'id desc';
     //入库查询
     $rs_count = db::field(parent::table, 'count(1)', $condition);
     $message = db::page_list(sql($option), $rs_count, $page, $page_size);
     //返回结果
     return array('num' => $rs_count, 'info' => $message);
 }
All Usage Examples Of db::field