I created a table in phpmyadmin and i was curious to know if it is possible to assign multiple values to one variable/field in the same table. For example here is what i have:

ID | Shoe   | Sizes
____________________
1  | CK     | 7
____________________
2  | LV     | 7
____________________
3  | Prada  | 7
____________________
4  | Nike   | 7
____________________
5  | Puma   | 7
____________________

This is what I want:

ID | Shoe   | Sizes
____________________________
1  | CK     | 7, 7.5, 8, 8.5
____________________________
2  | LV     | 7, 7.5
____________________________
3  | Prada  | 7
____________________________
4  | Nike   | 7, 8, 9
____________________________
5  | Puma   | 6, 6.5, 7
____________________________

I am not sure if i made any sense (i don't mind re-clarifying what i said).

Also, is there a technique in displaying a table on a web page? I tried using php and searched google to see if i could find any solutions but i only confused myself more. So how can i pull the data and display it on the site?

Thanks!

It would probably make sense for you to have two tables. Table 1 is there to define your products and the second table would be used to store quantities. The second table would also have a column that would be used as the foreign key. You build a relationship between the tabes when crafting your SQL queries.

Okay, so what if i were to do it in one table? I was aware that it is possible to do it in 2 seperate tables... but i was more interested in one table... got any ideas in that? If it isn't possible, i will change my plans and make 2.

anything is possible...

so if you want to store multiple values in one column, I'd say for you to pick a character that you know wont be a part of your data such as a comma or semicolon. You had picked a comma...fine.. you store the data as a string.

You select the data as you would normally using your SQL query, then you will need to parse through the data to extract the values. Your application code will handle making sense of the string of data. if you are using the comma as a deliminator then when you parse through the data and you see a comma, you know that the information after the comma is a new value.

Also, is there a technique in displaying a table on a web page? I tried using php and searched google to see if i could find any solutions but i only confused myself more. So how can i pull the data and display it on the site?

I have seen other questions on this site about taking data from SQL and displaying in a table format using PHP. try searching this site.

anyway, regardless of the server side scripting language, you simply need to make a connection to your data source, read the data and loop through the results. during the looping process, you can build your HTML table in insert the appropriate fields for each row. When you reach the end of the results, you close your DB connection.

This is what I want:

This is probably what you want to show on your site. If you use the two tables Jorge mentioned, that output is easily constructed with a single query on both tables (GROUP_CONCAT). Do not design your tables around what you want people to see, but how it's most easily maintained.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.