【问题标题】:laravel htmlentities() expects parameter 1 to be string, array given (raw sql count)laravel htmlentities() 期望参数 1 是字符串,给定数组(原始 sql 计数)
【发布时间】:2016-09-03 10:06:40
【问题描述】:

我在 laravel 中执行以下 sql 语句时出现以下错误:htmlentities() expects parameter 1 to be string, array given

public function index($id)
{
    $event = Task::find($id);
    //$tickremain = DB::select(DB::raw("SELECT artists FROM tasks where id='1'"));
    $tickremain = DB::table('tasks')->select(DB::raw('count(*) as thresholdc'))->get();

    return view('buy.index', ['event' => $event],['tickremain'=>$tickremain]);
}

我的看法:

<p>No. of Tickets remaining: {{$tickremain}}</p>

我想获得一个列字段的计数,但我留下了那个错误。

【问题讨论】:

    标签: arrays string laravel


    【解决方案1】:

    使用{{$tickremain-&gt;thresholdc}} 打印计数。

    【讨论】:

      【解决方案2】:

      你得到这个数组是因为 $tickremain 是一个数组。 htmlentities() 格式为

      string htmlentities ( string $string ). 
      

      所以只需尝试打印 $tickremain 并检查它是否是数组。如果是数组,只需像

      一样访问
      $tickremain['thresholdc']
      

      (基于数组)

      【讨论】:

        猜你喜欢
        • 2017-09-23
        • 1970-01-01
        • 2016-10-26
        • 2016-04-30
        • 1970-01-01
        • 1970-01-01
        • 2017-01-11
        • 2017-05-17
        • 2015-04-30
        相关资源
        最近更新 更多