mysql - Return random row in Laravel 4 -
i have testimonial table display on main page on laravel 4 project. usual run query random row:
select * `testimonials` `id`=".mt_rand(1,3);
but error when trying run it:
sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near '".mt_rand(1,3)' @ line 1 (sql: select * `testimonials` `id`=".mt_rand(1,3);) (bindings: array ( 0 => 1, ))
here controller:
public function showhome() { db::select('select * `testimonials` `id`=".mt_rand(1,3);', array(1)); return view::make('home.index', array('pagetitle' => 'home')); }
another side question how display information in home.blade.php template?
i usual while loop , $row['assoc_array']
$testimonial = db::table('testimonials')->where('id', mt_rand(1, 3))->first(); return view::make('home.index', array('pagetitle' => 'home', 'testimonial' => $testimonial));
this should provide variable called "testimonial" can use in view.
Comments
Post a Comment