I’m working on a small PHP/Javascript map application that is basically just pulling a bunch of location names and coordinate points from a MySQL database table and adding them to an HTML canvas. It’s supposed to represent locations visited by a character in an ongoing collaborative story, so I’d like to be able to also have the map retrieve the character’s position on the map at any given time and display this with a different icon.
The most obvious solution — since the character, like the map locations, has a name and coordinates — seems to be just including the character as their own row in the locations table as well, and having the map code recognize their unique information and display them differently. But since the character is not, in and of themselves, a location, storing them in the “locations” table seems weird. Creating a whole new table, “character”, just for this one row seems like overkill though.
So I guess my more general question is what is a good way for PHP/MySQL to deal with unique data like this, that is related to existing tables but not closely enough. Do I keep this data in a text file and update that with PHP?
There’s nothing particularly “weird” about having a table which is intended to have only a single row. Indeed, using a database for some of your data and a text file for other data would probably be a bit more weird.
Having a table also gives you the possibility of tracking character locations over time, if you ever need that information for any reason. (Better to track it and not use it than need it and not have been tracking it.)
If the position of the character is calculated on the spot and doesn’t need to be persisted then you can simply add it programmatically to the results from the database and it would be entirely transparent to both the database and the view. But if it does need to be persisted, a table is probably the way to go.