Jump to content
  • 0

Select characters for site.



I want users to be able to select their characters for transfers and such after they login, but I'm looking for info how to accomplish this.

if (!$die)
die('Could not connect: ' .mysql_error());
mysql_select_db("characters", $con);
$result=mysql_query("SELECT * FROM CHARACTERS WHERE ID=

This is where I run into the issue. How can I select the I'd to be dependant of their user name and to select I'd based off their account user name? Thanks to anyone that could help.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Kind of, but not all the way.

The ID is stored inside realmd, but the corresponding ID is also in characters.

mysql_select_db("realmd", $con);
$result=mysql_query("Select * from characters where id='[username_variable]")
echo $row[name];

And then from there if the user is player logged in under id 4 then I want it to select all characters under ID 4 and use the mysql_fetch_array and I may have just solved it after I figure out how to store a username variable as the account id. Maybe.

And you're right, I do have an ignorance of php and mysql haha.

Link to comment
Share on other sites

SELECT characters.* FROM characters.characters LEFT JOIN realmd.account ON (account.id=characters.account) WHERE account.username='antiroot'

this will fetch all rows from characters that have the same account ID in reference to the ID stored in the account table, the WERE clause determines which account username to use and by association which account ID to use

note: i'm not using SELECT * because that would fetch all the data from both tables, which you may not want to fetch the account specific data (username,passhash,email)

if you prefer not to use the JOIN syntax you can also use a subquery to select the ID from the account table

SELECT * FROM characters.characters WHERE account=(SELECT id FROM realmd.account WHERE username='antiroot')

Edit: also i would suggest only fetching the fields you actually need, no point wasting resources on data you'll not use

Another Edit: Note that my second example is not recommend because if the subquery returns more than 1 row you will run into issues, but since usernames are required to be unique there shouldn't be a problem using it for this case

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use