0

我试图count(message) As number让它在控制器端看起来没有错,但在视图端,我得到了那个错误:

Error rendering view: [home.index]

Undefined property: stdClass::$number

我的观点,我有这样的代码:

foreach($sorgu as $value)
{
    case 'BUL1':
    $sorgu99[0]+=$value->number;               
    break;
}

$posts = DB::table('xxx');

$posts = DB::table('xxx')->select( array('message', DB::raw('COUNT(message) AS number'), DB::raw('xxx.Time as time')));

$posts = DB::table('xxx')->join( 'xxs', 'xxx.smsCid', '=', 'rcs.smsCid', 'INNER');

$posts = DB::table('xxx')->where('xxs.status','=','1');

$posts = DB::table('xxx')->where( 'xxx.Time' ,'>', '2012-12-26');

$posts = DB::table('xxx')->where(DB::raw('length(message)'), '>', '3');

$posts = DB::table('xxx')->group_by('message');

$posts = DB::table('xxx')->get();
4

1 回答 1

2

每次调用 DB::table() 时都会进行新查询,因此上面代码中的每一行都在进行新查询,最后您只是从 xxx 表中获取所有帖子。试试这个:

$query = DB::table('xxx');
$query->select( array('message', DB::raw('COUNT(message) AS number'), DB::raw('xxx.Time as time')));
$query->join( 'xxs', 'xxx.smsCid', '=', 'rcs.smsCid', 'INNER');
$query->where('xxs.status','=','1');
$query->where( 'xxx.Time' ,'>', '2012-12-26');
$query->where(DB::raw('length(message)'), '>', '3');
$query->group_by('message');
$posts = $query->get();

数据库查询使用方法链。如果您想了解更多关于方法链的信息,ShawnMcCool 写了一篇关于它的好文章:http: //heybigname.com/2012/10/03/php-method-chaining/

于 2013-04-01T10:21:08.607 回答