CSVs, character management, and you
I haven't posted any new coding projects in a very long time, but I've been gradually chipping away at a concept that longtime readers will know by its working (joke) title of "Walmart Toyhouse," from the character management website Toyhouse. In theory, Walmart Toyhouse is a self-hosted character management script with enough automation that it's easy to maintain without being unnecessarily dense or hard to customize. I say "in theory" because progress on the code stalled for a while.
For me, the ideal character management system needs the following components:
- All information is pulled from a central database
- Page templates that you can reuse and reformat for multiple characters
- Some form of organization (folders)
- Galleries auto-populate from one central image database
It's not a complex idea on paper, but I didn't make much progress on it because I got stuck on implementing stuff like custom fields into a database. I also thought I had to code a browser interface for the whole thing, and that's a can of worms that I didn't have the energy to open (especially for a project with this many moving parts). So Walmart Toyhouse has been languishing in development hell for a very long time.
Cut to December 2024. I saw a post from Armaina floating the idea of a PHP and CSV character repository, and it singlehandedly solved nearly every problem I was having with my original conception of this code.
Per Armaina's post:
What I REALLY want is like, some stupid simple PHP code that utilizes a CSV file and not in a 'just post the array' sort of way. but (I don't know if there's a limitation to how CSV can be utilized, I don't know if I should be using XML or JSON as a database instead, but this is why I need people with knowledge to like actually talk to).
The end goal of all this, is not just to make a simple system for myself. But to also provide a system that anyone with limited knowledge can use. All they would have to do is follow a template to make their 'database' in any spreadsheet editor and save it as a CSV and then plug in all the necessary information into the code and that's it. If they want to add more characters or more tags they can do it in their spreadsheet editor and not have to mess with the code at all beyond the setup.
This is more 'evergreen' and less daunting than manually coding each character page by hand or using a log-in interface to manage that can be prone to all sorts of additional vulnerabilities.
All of my publicly available PHP scripts are CSV-based, but I was so hung up on the idea of a browser interface that I didn't consider the possibility of just... editing the CSV file directly. Unlike my other scripts, a character management system doesn't require any end-user input, so why not handle all the database management stuff locally?
This got me excited about Walmart Toyhouse again, and I started thinking about what I could do with just the CSV file and really simple code. I've also been talking to Armaina about features she would want as a user. It's been fun getting to know how someone else organizes their characters — it can feel pretty insular doing everything yourself in this space, and you definitely develop some blind spots after a while!
Armaina's post and my subsequent conversations with her have clarified my feature list:
- All information is pulled from one CSV file whose columns can include whatever fields the user would like
- Page templates that you can reuse and reformat for multiple characters; they must be able to accommodate the custom fields in the CSV
- Characters should be filterable with folders and/or tags. Tags can span multiple categories (gender, species, pronouns, origin, etc)
- Galleries auto-populate from one central image database (also a CSV)
Now that I don't have to work with a standardized database format, a lot of this stuff has fallen into place pretty easily. You can turn a CSV file into an associative array in a few lines of code. From there, you can output values from that array using echo
statements that reference the column titles (which are user-determined) from the CSV.
For example, if your CSV looks like this:
id,name,species,alignment
1,"Drizzt Do'Urden",Drow,"Chaotic Good"
2,"Spiders Georg",Human,"Chaotic Neutral"
You could output that information in your page template code like this:
<table>
<tr>
<td>Name:</td>
<td><?php echo $character['name']; ?></td>
</tr>
<tr>
<td>Species:</td>
<td><?php echo $character['species']; ?></td>
</tr>
<tr>
<td>Alignment:</td>
<td><?php echo $character['alignment']; ?></td>
</tr>
</table>
Is this the slickest or most best-practice-compliant way to execute this? Definitely not, but it's simple enough for someone without any coding knowledge to tinker with. (Also, nothing I've coded has been particularly slick or best-practice-compliant, so it's tradition at this point.)
I've been using my Arknights operator list to test the code out, so now that page runs out of one PHP file and the CSV just as I've described. Pretty cool!
At this point, I'm just stuck on implementing the tags. I've done some basic tagging systems with PHP before (and written a basic tagging tutorial, even), but implementing them across multiple (custom!) categories in a way that doesn't involve a million lines of spaghetti code is stumping me. In the spirit of Armaina's original post, I'm going to continue crowdsourcing ideas for this code. Feel free to email me or drop a comment if you have any proposals.
The beauty of this is that the same code can be used for basically anything that involves collecting shit in a list and spitting it out onto a page... like my image gallery system. I had been agonizing over porting that one over into SQL and making a secure browser interface for it, but the CSV system streamlines it significantly and makes it more customizable. I know there's been quite a bit of interest in the image gallery code, so I would be open to releasing a beta version without detailed tagging if there's interest. (That offer also applies to Walmart Toyhouse itself! Let me know!)