How does PHP enable automatic classification of mysql data tables?

Source: Internet
Author: User
How does PHP automatically classify mysql data tables? There are two table item data table & nbsp; goods: title, item title. Brand, brand idid & nbsp; title & nbsp; & how does nbsp PHP enable automatic classification of mysql data tables?
There are two tables

Product data table goods: title, product title. Brand, brand id
Id title brand
1 cosmetic L'Oreal 65 1
2 cosmetics Wen Biquan 75
3 cosmetic Yarina 45
4 cosmetics Chanel 45 2
5 cosmetic oshiman 22

Brand
Id name
1 L'Oreal
2 Chanel
3 Wen Biquan
4 Yarina
5. ou Shiman


Use the PHP and SQL statements to automatically obtain the brand id for the goods table without the brand id. for example, the brand value after the item table id2 is 3. I don't know how to do it. Which gives me a thought. In fact, there are hundreds of brands in the brand list, and the product name must include a brand name. Php mysql SQL
------ Solution --------------------
Traverse the title in the goods table to check whether the name in the brand is included. If yes, write down the id and put it into a new array as the brand value of the title. you can try it.
------ Solution --------------------
Study the orm.
------ Solution --------------------
The stupid way is. Use substr to extract 3-6 characters. Obtain the brand names such as "L'Oreal" and "Chanel" and query the corresponding brand_id in the brand table .. The premise is. Your 3-6 character string is exactly the brand name.
------ Solution --------------------
Substr ($ str, 9, 9); it is a Chinese string. If the brand begins with the fourth Chinese character. Then, it intercepts 9 characters,
Foreach ($ brand_name as $ key => $ item ){
$ Name = substr ($ str, 9, 9 );
Switch ($ name ){
Case 'oreal ':
// Do something;
$ Brand_name [$ key] ['brand _ id'] = 3;
Break;
Case 'XXX ':
}
}
I don't know if it's what you want...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.