Jump to content

Add new field with names


Patte12

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.