NiTx Posted October 10, 2013 Share Posted October 10, 2013 I have two tables, brands and devices. brands table is set up like so: id | brand_name 1 Apple 2 Samsung devices: id | brand_id | dev_model | dev_version 1 1 iPhone 5s 2 2 Galaxy S4 Right now I can search for a phone by its device name, for example: 'iPhone 5s', but I need my users to be able to search for the brand too: 'Apple iPhone 5s'. Is there a practical approach to doing this without having to add the brand names in my device table? This is my current MySQL query: $sql = "(SELECT id, brand_id, dev_model, dev_version FROM devices WHERE "; $sql .= "CONCAT(dev_model, ' ', dev_version) LIKE '%{$database->escape_values($term)}%' "; $sql .= "LIMIT 4)"; Any help would be appreciated, or even a point in the right direction. Quote Link to comment Share on other sites More sharing options...
Solution NiTx Posted October 11, 2013 Author Solution Share Posted October 11, 2013 Solved the issue. Discovered LEFT JOIN. As with most of my php problems, I just don't know what to search in Google to find the answers to my issue.. For anyone else with the same issue this is how I solved my issue. $sql = "(SELECT devices.id, devices.brand_id, devices.dev_model, devices.dev_version, devices.dev_model_number, devices.dev_release_month, devices.dev_release_year, brands.brand_name FROM devices "; $sql .= "LEFT JOIN brands ON devices.brand_id = brands.id "; $sql .= "WHERE CONCAT(brands.brand_name ,' ', devices.dev_model, ' ', devices.dev_version, ' ', devices.dev_model_number) LIKE '%{$database->escape_values($term)}%' "; $sql .= "ORDER BY devices.dev_release_year DESC, devices.dev_release_month DESC LIMIT 4)"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.