hey, i want to created an sql statement with rails for a search engine this is the code, u can search on first name and last name firm_id = @session[:user].id #last_name = params[:employee][:last_name] #first_name = params[:employee][:first_name] last_name = "Creytens" first_name = "b" @employee_pages, @employees = paginate (:employee, :conditions => ["firm_id = ? and first_name like ? and last_name like ?" , firm_id, first_name, last_name] , :order_by => "last_name ASC", :per_page => 10) i have a few question: -how can i make, that the user doesnt need to fill in the full name, just 1st or a couple of letters, in php i can use the % ==> ''%first_name%'', seems not to work here -the search engine is on the same page as the results, but the first time the parameters arent there, so i just want to show all employees, if the parameters are there then i show those. How can i check if the parameters are there, in php u can u isset( *_POST["last_name"] ), what is that here?
rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
2005-Sep-27 14:42 UTC
Re: sql statements and parameter
Hello Nick, You could have waited a bit more before sending a new message, but it''s ok. Nick Brutyn said the following on 2005-09-27 09:02:> firm_id = @session[:user].id > #last_name = params[:employee][:last_name] > #first_name = params[:employee][:first_name] > last_name = "Creytens" > first_name = "b" > @employee_pages, @employees = paginate (:employee, :conditions => > ["firm_id = ? and first_name like ? and last_name like ?" , firm_id, > first_name, last_name] , :order_by => "last_name ASC", :per_page => 10) > > i have a few question: > > -how can i make, that the user doesnt need to fill in the full name, just > 1st or a couple of letters, in php i can use the % ==> ''%first_name%'', > seems > not to work hereYou can, you just have to give the right parameters to the query engine: :conditions => [''first_name like ?'', "%#{first_name}%"]> -the search engine is on the same page as the results, but the first time > the parameters arent there, so i just want to show all employees, if the > parameters are there then i show those. > How can i check if the parameters are there, in php u can u isset( > *_POST["last_name"] ), what is that here?params[:last_name].blank? Bye ! François