php - how to select items that concatenation of two rows is like input -
i have mysql table, users: (id, first_name, last_name, ....)
i'd pseudo query
select * users first_name.' '.last_name = 'john doe' limit 10") i want cause have lots of trouble spliting string (then don't know in order user typing'
this current, not working good
$phrase = explode(' ',$term); $last_name = ''; if($phrase[1] != '') $last_name= " or last_name '%".$phrase[1]."%'"; $qstring = "select usuarios.first_name,usuarios.last_name, usuarios.id id usuarios first_name '%".$phrase[0]."%' or last_name '%".$phrase[0]."%' $last_name limit 5"; any suggestion achieve (by concatenating @ query or spliting @ php) apreciated
you can concatenate in mysql query using concat:
select * users concat(first_name,' ',last_name) = 'john doe' limit 10 in code become:
select * usuarios concat(first_name,' ',last_name) '%{$phrase[0]}%' limit 5
Comments
Post a Comment