开发者

php/MySQL compare columns

I am new to MySQL queries and a beginner at PHP, so I would love some help with this qu开发者_如何学运维estion.

Here is my scenario: I have a system that allows users to save favourite items to the database. These items have about 20 different features (db columns) and only some features are included for each item.

What I want to do is write a query that looks at the users favourite items and compares them to other entries (rows) in the database and if they have the same number of features or more, I want the system to create a PDF and email it to them. Each feature column has the text "in" if it's included.

I don't need help with the PDF or email portion, just the MySQL/PHP portion.

I would very much appreciate any help, insight, or SQL queries that would be of help. Thank you for your time.

Update:

Thanks for your quick reply. I, however, am still confused and I actually left out a detail. In some of the fields, there is the text n/a, so the values not null, but I don't want it to be included. What is an "FK to the item". Are there any ways to counting the columns that include the text "in", instead of the reverse - counting all null values? Any examples of code would be amazing.

Thanks for your help.


I am assuming you have a FK to the item in your features table. You should set the default value of each of your feature column to NULL, then use the query from How to count all NULL values in a table? which has a query that will give you a row and the count of all NULL columns. Simply run through that and you'll know how many features are active for each item.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜