How to update this kind of data using php?(0-0-0-0-0)

4 replies
Guys I really need your help,

Im modifying a script but dont know how to update this kind of data:

So the sql table is "towns" and I want to update "resources" the data under resources is 0-0-0-0-0 (food-water-stone-wood-gold)

So lets say I want to update gold only? how can I do that? Please help me guys
#data #kind #php00 #update
  • Profile picture of the author michael_gourlay
    From what you describe, it seems that all that data (food-water-stone-wood-gold) is stored in one column? If that's the case, you need to pull that info, split it up into separate variables, change the one you need, create a new string with all the data and update the correct record in the DB. Can you change the structure of the DB? That sounds like an awful way to store the data. What if you have to sort multiple records on wood?
    {{ DiscussionBoard.errors[5441676].message }}
  • Profile picture of the author Anthoni
    I agree with Michael that is an awful way to store data inside any database. However, from what I can tell I would guess that they are bit flags and used in the mapping of tiles in the game (think Civilization here).

    What you need to really do is find the person who wrote it and first slap them for using such awful techniques AND then get them to alter it. If that is not possible then I would look into getting another programmer to help you with this.
    {{ DiscussionBoard.errors[5441855].message }}
  • Profile picture of the author ussher
    if there is a fixed amount of these type of data structures:
    (food-water-stone-wood-gold)

    You could move all the unique ones out to a different table with a key
    1 | (food-water-stone-wood-gold)
    2 | (food-water-stone-wood-bears)
    3 | (food-water-stone-wood-flower)
    4 | (food-water-stone-wood-honey)

    Then use the key in the current table where the (food-water-stone-wood-gold) currently is. Then to update it, you would just change the key from say 1 to 3 to change the full set.
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[5446082].message }}
  • Profile picture of the author 723Media
    You've already been reprimanded about the bad data structure but assuming you can't change that, @michael_gourlay is right.

    You would need to pull the data out of the database, split it into an array on '-', update the value in the array that you need to update, rejoin the array into the correct string format, then put it back into the database.

    Depending on the language you're developing in, you should search how to split a string into an array based on a delimiter or character. That should get you started.
    {{ DiscussionBoard.errors[5449987].message }}

Trending Topics