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:
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);
}
}
I have also tried:
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() 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
Route::get('/', array(
'as' => 'home',
'uses' => 'HomeController@showWelcome'
));
You need to change the order of the chaining to put the where() function before the get() function. Anything after get() will be applied to an Collection rather than the Query Builder.
If you want to pass a parameter through the URL try:
// routes.php
Route::get('/{wab_id}', array(
'as' => 'home',
'uses' => 'HomeController@showWelcome'
));
Also, the where() constraint should be before the get() method.
Now you should be able to accept the URL parameter as an argument into your HomeController#ShowWelcome function
class HomeController extends BaseController {
public function showWelcome($wab_id) {
$id = $wab_id;
// where() constraint before the `get()` method.
$results = DB::Table('films')->where('wab_id','=', $id)->get();
print_r($results);
while ($row=mysql_fetch_array($results)) {
$url = $row['url'];
}
return View::make('hello')->with('row', $url);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With