I need help with a select, but before asking the question, I will give a short description of how my system works:
tables I want to do the select, has a many-to-many relationship, look below:
table product:
prd_cod(pk) //stores the product code ex: 0,1,2
cat_cod(fk)
prd_name //stores the product name, ex: tv, gps, notebook
table description_characteristc:
prd_cod(fk)
id_characteristic(fk)
description //stores the description of the characteristic, ex: sony, 1kg, hj10
table characteristic:
id_characteristic (pk)
name_characteristic //store the name of characteristic, ex: brand, weight, model
i have ready made in the index.php, a suggest jquery, that every word I type it’s calls a php file that makes a select and returns the result, limit of 10, but this suggest I got a ready made in the internet, therefore it’s select does not match with my business rule, however I would like to implement a new select to this suggest.
the select with like ‘%’, have to bring to the suggest box the prd_name and all description, of table description_characteristc. when the user click on the result will be sent per parameter to the other .php but this i dont need now,
when the user type ‘tv’, the select will bring the result:
tv
tv led
tv plasm
tv samsumg
and when the user type ‘tv s’, the select will bring the result:
tv sony
tv samsumg
tv salom
tv sxxxx etc
remembering that prd_name stores only ‘tv’
Try this query, which joins the two tables together. The first part of the where clause will reduce the number of rows from the product table and the second part will match relevant descriptions.
Note: this query may not be particularly efficient.