Patte12 Posted July 20, 2012 Share Posted July 20, 2012 Hello. I'm really new to PHP/MySQL and I wanna add a new field in the structure of a table named items, it should contain allot of item names like this: Item1, Item2, Item3, Item4, ... and i need to be able to add, remove and return the names. (I'm using PHPMyAdmin 2) - What type should the "items" be when i add it as a field inside a table's structure?, should it be a 'enum' or something?. - And how do i add a name to the list?, like SET += [newname]?. - And is it possible to make the names (Item1, Item2..) return like this: Item1 Item2 Item3 ... I know this is ALLOT to ask for but i really need help with this! i would really appreciate it if anybody could help me! Quote Link to comment https://forums.phpfreaks.com/topic/266014-add-new-field-with-names/ Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Items would probably be a VARCHAR Grabbing items from a database is pretty straightforward. There are many tutorials on this, and even examples directly in the manual. IMO, you should read about theory before trying to jump in to this. Quote Link to comment https://forums.phpfreaks.com/topic/266014-add-new-field-with-names/#findComment-1363145 Share on other sites More sharing options...
Patte12 Posted July 20, 2012 Author Share Posted July 20, 2012 Got it all working now! But i don't know how many items there is gonna be, so what should i set the VARCHAR(???) to? can i just say (max) if so, how many is that? Quote Link to comment https://forums.phpfreaks.com/topic/266014-add-new-field-with-names/#findComment-1363174 Share on other sites More sharing options...
Barand Posted July 21, 2012 Share Posted July 21, 2012 You need to normalize your data... TABLE A +-----+--------------------------+------------+ | ID | ITEMS | OTHER | +-----+--------------------------+------------+ | 1 | item1, item2, item3 | abc | | 2 | item5, item1 | xyz | +-----+--------------------------+------------+ should be TABLE A TABLE B +-----+------------+ +---------+---------+ | ID | OTHER | | A_ID | ITEM | +-----+------------+ +---------+---------+ | 1 | abc | | 1 | item1 | | 2 | xyz | | 1 | item2 | +-----+------------+ | 1 | item3 | | 2 | item5 | | 2 | item1 | +---------+---------+ ... so the items are in a separate table, one per row, each with the id of the parent row from table A Quote Link to comment https://forums.phpfreaks.com/topic/266014-add-new-field-with-names/#findComment-1363324 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.