Jump to content

Recommended Posts

Posted

Hello, I am working on a website that has a search functionality.

 

I am trying to search multiple tables and multiple fields from each table with 1 query.

 

The 1 field that connects each table with each other is "account_num"

 

can anybody help me create a query to search multiple tables at once and then return results for it?

 

here: is my query......

$sql = "SELECT " . TABLE_USERS . ".account_num, " . TABLE_USERS . ".username, " . TABLE_PERSONAL . ".account_num, " . TABLE_PERSONAL . ".first_name, " . TABLE_PERSONAL . ".middle_initials, " . TABLE_PERSONAL . ".last_name, " . TABLE_PERSONAL . ".birthday, " . TABLE_PERSONAL . ".city, " . TABLE_PERSONAL . ".province, " . TABLE_PERSONAL . ".postal, " . TABLE_PERSONAL . ".country, " . TABLE_PROFILE . ".account_num, " . TABLE_PROFILE . ".pro_des, " . TABLE_PROFILE . ".title, " . TABLE_PROFILE . ".company_name, " . TABLE_PROFILE . ".industry, " . TABLE_PROFILE . ".contact_address, " . TABLE_PROFILE . ".contact_email, " . TABLE_PROFILE . ".about, " . TABLE_PROFILE . ".career_path, " . TABLE_PROFILE . ".career_prep, " . TABLE_PROFILE . ".challenge, " . TABLE_PROFILE . ".strengths, " . TABLE_PROFILE . ".accomplishments, " . TABLE_PROFILE . ".change_working_condition, " . TABLE_PROFILE . ".pro_goals, " . TABLE_PROFILE . ".inspired_me, " . TABLE_PROFILE . ".known, " . TABLE_PROFILE . ".orgs, " . TABLE_PROFILE . ".honors, " . TABLE_PROFILE . ".i_support, " . TABLE_PROFILE . ".hobbies, " . TABLE_FAVORITES . ".account_num, " . TABLE_FAVORITES . ".author, " . TABLE_FAVORITES . ".book, " . TABLE_FAVORITES . ".movie, " . TABLE_FAVORITES . ".tv_show, " . TABLE_FAVORITES . ".song, " . TABLE_FAVORITES . ".color, " . TABLE_FAVORITES . ".vacation_destination FROM " . TABLE_USERS . ',' . TABLE_PERSONAL . ',' . TABLE_PROFILE . ',' . TABLE_FAVORITES . " WHERE " . TABLE_USERS . ".account_num, " . TABLE_USERS . ".username, " . TABLE_PERSONAL . ".first_name, " . TABLE_PERSONAL . ".middle_initials, " . TABLE_PERSONAL . ".last_name, " . TABLE_PERSONAL . ".birthday, " . TABLE_PERSONAL . ".city, " . TABLE_PERSONAL . ".province, " . TABLE_PERSONAL . ".postal, " . TABLE_PERSONAL . ".country, " . TABLE_PROFILE . ".pro_des, " . TABLE_PROFILE . ".title, " . TABLE_PROFILE . ".company_name, " . TABLE_PROFILE . ".industry, " . TABLE_PROFILE . ".contact_address, " . TABLE_PROFILE . ".contact_email, " . TABLE_PROFILE . ".career_path, " . TABLE_PROFILE . ".challenge, " . TABLE_PROFILE . ".strengths, " . TABLE_PROFILE . ".accomplishments, " . TABLE_PROFILE . ".change_working_condition, " . TABLE_PROFILE . ".pro_goals, " . TABLE_PROFILE . ".inspired_me, " . TABLE_PROFILE . ".known, " . TABLE_PROFILE . ".orgs, " . TABLE_PROFILE . ".honors, " . TABLE_PROFILE . ".i_support, " . TABLE_PROFILE . ".hobbies, " . TABLE_FAVORITES . ".author, " . TABLE_FAVORITES . ".book, " . TABLE_FAVORITES . ".movie, " . TABLE_FAVORITES . ".tv_show, " . TABLE_FAVORITES . ".song, " . TABLE_FAVORITES . ".color, " . TABLE_FAVORITES . ".vacation_destination LIKE '%$search%' AND " . TABLE_USERS . '.account_num='.TABLE_PERSONAL.'.account_num AND ' . TABLE_PROFILE . '.account_num=' . TABLE_FAVORITES . '.account_num';

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...