Click to See Complete Forum and Search --> : MySql Arrays?


BigMoosie
09-07-2005, 01:20 AM
..

NogDog
09-07-2005, 02:13 AM
You could use implode() to convert a numerically indexed array into a string, and save that in a single row (then use explode() to reverse the process when you read that row into your script from the DB). But if you have an associative array, then you'd either need to come up with something more complex to embed the keys in the string as well, maybe so it looks like:

"key1=value1|key2=value3|key3=value3"

In this case, it might be simpler to just create a separate table for that array?

I guess without knowing why you need to do this, it's hard to be sure what the best solution is.

BigMoosie
09-07-2005, 02:35 AM
..

NogDog
09-07-2005, 10:44 AM
I think I might be inclined to use two tables. One would hold static info for each game: game_id_nbr, player_1, player_2, datetime_started, etc....

Table 2 would record moves, one move per row, using game_id_nbr to relate each row to its game, so the fields would be something like game_id_nbr, turn_nbr, move.

Then if you wanted to list the move history for a given game, the query would be something like:

SELECT * FROM `moves` WHERE `game_id_nbr` = '$game_nbr' ORDER BY `turn_nbr`;