Jump to content

How to fetch MySQL tables into a list


Recommended Posts

I am currently creating a roleplay server, and I have managed to create 3 factions through MySQL (on phpmyadmin). I am just wondering how I'd allow players to join these factions, and how to fetch these factions into a list, through a command such as /factions.

Thanks for taking the time to read and possibly help!

Link to comment
Share on other sites

Without writing source code for you, the process is fairly simple if you just want to list these factions and print them to the user.

  • Create an SQL query to fetch these faction names from your table. (SELECT <columnName> FROM <tableName>...etc)
  • Execute it via whatever MySQL bridge you are using.
  • This will usually return a ResultSet of some form, which you can loop through and stack onto your instantiated list.
  • Loop the list, printing out in whatever format you want to the user.

Feel free how to google how to loop through rows for whatever SQL bridge you are using, e.g. mysql2 for node, MySqlConnector for nuget.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...