I need some help for a complex query. I'm using autocomplete jquery-ui for search some users and php+mysql to search.
Users can register with his first_name, last_name and email (requiered fields) on a wordpress/buddypress page.
so, is easy search with regexp on an example that i find on stackoverflow, but i want a make a complex query to search by first_name or last_name or email.
first_name and email are in wp_users table and last_name is in wp_bp_xprofile_data table. i don't want make a custom meta to join names and emails so,
To obtain the first_name and email, the query is:
SELECT * FROM wp_users WHERE display_name REGEXP '^$param' OR user_email REGEXP '^$param'
and to obtain de last_name, the query is:
SELECT value FROM wp_bp_xprofile_data WHERE field_id = 5 AND user_id = ".$id."
(value is last_name's result and $id=wp_users.ID)
How can a mix this queries?
if we see this like one table it would be like :selec * from users where first_name=regexp or last_name=regexp or email=regexp (basically), but by the complex structure of wordpress/buddypress i can't do this. please help!!!
eg...3 users, the name of the first user is oscar, the last name of the second user is osbourne, and the email of the third user is [email protected], if the search starts with 'o', the query will find this 3 users.
PS: i forgot but i need to return the id, first name, last name and email.
Bonus: i'm using the regexp ^$params to find the string at the begin characters. what regexp is better to find this on the everywhere results?