php - laravel 4 preg_replace() : Parameter mismatch

标签 php mysql laravel

我试图将 2 个不同表的值存储在一个数组中,然后在 View 中显示值。我有 2 个表“汽车”和“类”。 Table cars 有一个名为“class”的字段,其中包含类表的 id,table class 有字段“class”和“id”。我正在进行以下查询:

public function edit($id) {
    $data['values'] = DB::select('select * from cars where id = ?', array($id));
    $class = DB::select('select class from cars where id = ?', array($id));  
    $data['class']= DB::select('select class from classes where id = ?', array($class)); 
    $data['classes'] = DB::table('classes')->orderBy('class', 'asc')->distinct()->lists('class', 'id');
    return View::make('pages.edit', $data);
}

在 View 中:

<div class="form-group">
    {{ Form::label('class', 'Class', array('class'=>'control-label col-lg-4')) }}
    <div class="col-lg-8">
        {{ Form::select('class', $classes ,$class->class,array('class' => 'form-control') ) }} 
    </div>
</div>

在 $class 中,我想保存该特定汽车的类 ID。如果没有内部连接,还有其他方法可以做到这一点吗?它显示以下错误:

preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

最佳答案

// this returns array(stdClass('class'=>'classValue'))
$data['class']= DB::select('select class from classes where id = ?', array($class)); 

// so simply do this:
$classArray= DB::select('select class from classes where id = ?', array($class)); 
$data['class']= $classArray[0];

关于php - laravel 4 preg_replace() : Parameter mismatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23340822/

相关文章:

php - 正则表达式中 '\G' anchor 有什么用?

javascript - 从 Bootstrap slider 获取变量

php - 我想获取一个 id 的所有父 id 的数组

Laravel 的 whereBetween 不包括日期

mysql - 按类别中项目的下载次数对类别进行排序

javascript - "$.get"用于检索信息

python - 如何基于 Flask mega 教程在 pythonanywhere 上设置 Flask

mysql日期范围,较大日期在较小日期之前

php - 使用 WordNet 创建一个简单的字典

Laravel 混合版本控制不会删除旧的构建文件