Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recording Multiple Values

Status
Not open for further replies.

Xploder

Programmer
Apr 10, 2005
11
CA
Hi, I'm trying to save as many integer values as possible for any user into a table.

Ex: Fist the user starts out with no additional values other than their name and password, and the iteam field is blank. And then if the user buys something it should record that into the iteam field, and when the user buys again it'll add on values in the same field.

If you have any Idea on how to achive that, please respond.
Thank in advance.
 
If you mean you want the field to be incremented by a specified quantity, then you could use:[tt]
UPDATE tablename SET iteam=iteam+quantity[/tt]
 
So I need to use the SET datatype? So after incrementing the length how would I add in a value?

I'll try to explain a bit more: I don't clearly know yet how MySQL works but in other programming laguages I can create a flexible 1D array with an inicial length of 1 and then increase the length of the array when values are added.

How can I achive the same thing?
 
no, in tony's example, SET is not a datatype

could you give an example of the contents of the field after it has been updated twice?

if there are any commas in there, you may not want to do it that way, depending on what you're thinking of using it for

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts May 8 2005)
 
I think we're talking about two different things here; forget my previous answer.

Are you saying you want to store a list of items in one field? That is possible, by using a string containing the values separated by commas and adding to the end of the string every time, but it is usually very bad database design; it could cause massive problems later. What you would need is a separate table with a record for each user/item occurrence, adding a record to the table for every item purchased.
 
TonyGroves, I'll make a new table for every iteam. But you can buy an iteam twice, even with a different value, so how do I record that?

I'm making a webbased game where you can buy land, each piece of land has a different value from 1-255, now when you buy land I want it to add the lands value to the user that owns it. I'll also make a cellective table to show all the land that has been bought.
 
you would 2 tables one with

userstb
id | username | password

orderstb
id | userid | iteam | dateordered

you would then just store the id from the userstb into the userid field

when you want to know how much purchased do a sum query, when you want to know how many times purchased do a count with a where userid = whatever, etc
 
Ok, I got it to work using steven290's methond, thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top