I am fetching data from product detail table but i don't want to fetch all the columns from the table as i want to make a dynamic product detail page which will display the data directly from the table whenever we add a new column so that we don't have to make any changes in the code.
Asked
Active
Viewed 90 times
1
-
3Specify the columns that you want during `SELECT` – Carl Binalla Nov 05 '18 at 07:37
-
1Just specify all the column name(s), which you want to fetch in the `Select` – Madhur Bhaiya Nov 05 '18 at 07:37
-
2Anyways, your table structure seems to be suffering from bad design. Consider normalizing it. – Madhur Bhaiya Nov 05 '18 at 07:37
-
1I agree with @MadhurBhaiya; if you frequently need to add new columns, you should take a good look at the table design. For example a table that only stores product properties might make your application a lot more flexible. – jeroen Nov 05 '18 at 07:40
1 Answers
1
You have a horrible table structure. Try something like this...
id, field_name, data
CREATE TABLE `fieldstore` (
`id` int(11) NOT NULL,
`field_name` varchar(100) NOT NULL,
`field_data` varchar(200) NOT NULL
)
Example data: 1, "blend", "bamboo" (The 1 is of course auto-increment).
This way, you can have an unlimited number of field names without having to alter your table structure every time you wanted to add a new column.

Difster
- 3,264
- 2
- 22
- 32
-
1Please add some sample data to your answer, so that OP can understand what you really mean. +1 ; `Create Table` statements would also be handy – Madhur Bhaiya Nov 05 '18 at 07:42
-
Also worth a read - https://stackoverflow.com/questions/4066463/should-i-use-eav-model – Nigel Ren Nov 05 '18 at 07:44