在非对象Laravel 4.2上调用成员函数where()
我正在尝试使用和传递给URL
的id
来编辑查询,但是在尝试运行代码时出现错误:
I am attempting to use and id
that being passed into the URL
to edit the query but when attempting to run the code I get an error of:
在非对象上调用成员函数where()
Call to a member function where() on a non-object
控制器
class HomeController extends BaseController {
public function showWelcome() {
$id = intval($_GET['wab_id']);
$results = DB::Table('films')->get()->where('wab_id','=', $id);
print_r($results);
while ($row=mysql_fetch_array($results)) {
$url = $row['url'];
}
return View::make('hello')->with('row', $url);
}
}
我也尝试过:
class HomeController extends BaseController {
public function showWelcome() {
$id = intval($_GET['wab_id']);
$results = DB::Table('films')->get()->where('wab_id', $id);
print_r($results);
while ($row=mysql_fetch_array($results)) {
$url = $row['url'];
}
return View::make('hello')->with('row', $url);
}
}
仅会引发相同的错误消息,这是唯一未引发错误但返回错误为的代码段:
Only to be thrown the same error message and this is the only snippet that has not thrown the error but returns with a error of:
mysql_fetch_array()期望参数1为资源,给定对象
mysql_fetch_array() expects parameter 1 to be resource, object given
class HomeController extends BaseController {
public function showWelcome() {
$id = intval($_GET['wab_id']);
$results = DB::Table("SELECT * FROM next WHERE wab_id=$id");
while ($row=mysql_fetch_array($results)) {
$url = $row['url'];
}
return View::make('hello')->with('row', $url);
}
}
路线
Route::get('/', array(
'as' => 'home',
'uses' => 'HomeController@showWelcome'
));
我试图将std Obj数组传递给视图,但是我必须设置wab_id,因为如果没有,我接下来将得到wab_id的未定义索引
$arrays = json_decode(json_encode($results), true);
为了将使用查询获取的std数组转换为多数组,然后遍历该数组,并且有效
i was trying to pass an std Obj array to the view, but i had to set wab_id because if not i would get a undefined index of wab_id next i
$arrays = json_decode(json_encode($results), true);
in order to get the std array that i was getting with using the query into a multi array then looped through the array and that worked
感谢大家的帮助.
控制器
class HomeController extends BaseController {
public function showWelcome(){
$id = isset($_GET['wab_id'])?$_GET['wab_id']:"";
$results = DB::Table('films')->where('wab_id', $id)->get();
$arrays = json_decode(json_encode($results), true);
foreach ( $arrays as $film ) {
}
return View::make('hello')->with('film', $film);
}
}