Getting Started with Flat Databases and PHP (and tag sorting)

I would like to make my own character sorter on my website similar to something like this:
https://toyhou.se/armaina/characters/tags:1/taga:1/folder:all
(it doesn’t need to function exactly the same but this is just one visual example.)
I want to make a list of tags that the user can toggle on or off at the same time and in doing so it pulls from my list of characters

I’d like to make it using PHP and CSS utilizing a flat database format of some kind (CSV, JSON, XML, if I can make it in a spreadsheet then I’m not picky)

The problem is that I don’t know where to start. Most my knowledge of PHP is editing existing code so I know I have my work cut out for me, but the big thing is I don’t know what properties I would need to research to do such a thing and that makes it difficult to even know what to search for. (especially since searching for ‘tag’ doesn’t exactly narrow it down, is the filter property that I need? Is there something different? I have no idea!!! )

For that matter, I have no experiencing working with a flat file databases at all, so if anyone has any guides or direction or insight on working with this, that would also be helpful (please no videos tutorials, I prefer text-based guides with a lot of screenshots)

I work best with templates or example code so that I can actually see a thing in action and play with it, if anyone knows of any to toss my way that would be extremely helpful. It can be tag sorted or not, I just need simple things to break down and learn the basics of.

My goal is to eventually make a template that other creators can use that all they have to do is make a spreadsheet of their characters and desired tags and export and plug in the related files to give a low-impact way for making a vast character repository on any PHP-supporting host.

(slight aside, do you think this section would benefit from a catch-all database tag?)

Hi, armaina. I don’t use PHP much myself, but it looks like you might want to start with PHP’s fgetcsv() function.

1 Like

Thank you, that at least gives me a place to start with using PHP with an CSV

1 Like

Sounds fun! A lot of people find it helpful to have tasks like this broken down for them a bit, so here’s a few components to what you’re doing and some links:

  • Retrieving CSV text from a file PHP: file_get_contents - Manual (I’m guessing that just reading your spreadsheet from CSV is sufficient and that you don’t need to write new items to it at this stage)
  • Converting data from CSV text to an array php - CSV to Associative Array - Stack Overflow so that you can access characters and their data this way: $characterSpreadsheet[$currentIndex]['name']
  • Retrieving the user’s search request and getting the search parameters (multiple ways to do this, but it might be good to start with a simple form PHP Form Handling)
  • Searching through the array of characters for ones which match your search criteria (tags, etc) PHP: array_filter - Manual
  • Looping over your array and rendering the HTML / returning data via a web request (I’m assuming you got this part covered already)

yes! this is fantastic! exactly the kind of breakdown I was hoping for! Thank you so much!

And yeah I don’t want or need to do any server-side writing to the CSV, I’ll be making the CSV by hand and uploading the new one as-needed.

Also, are toggle buttons used in this manner considered a type of search request? I ask because there will be no manual inputs for this, just a fixed set of toggle-able settings that are based on the CSV file I’m making.

Yeah that’s still a search request, though it doesn’t have to be a form; in the example site you linked, it puts the search terms in the page URL instead of the request body, and each tag button is just a link to the current page with that tag added/removed from the URL. Depending on how you look at it, this complicates things a bit since you need to then parse the URL to extract the list of tags and do your filtering, but it could be worth doing.

aah okay that makes sense

All that matters to me is the function, as far as how to achieve it I’m flexible with provided it it’s PHP and CSS related