Page 1 of 1

[HELP]PHP MySQL

Posted: Wed Sep 22, 2010 4:15 pm
by Wingtsun247
Hello ! I need to do the fallowing thing with PHP MySQL:

The script should use two tables - account and characters

First it should - SELECT `id` FROM `accounts` WHERE `username`='$username';

And then it should use that returned id to get name from characters Database with that id

Please help, cant get this work ;(

Re: [HELP]PHP MySQL

Posted: Wed Sep 22, 2010 7:53 pm
by buckit
ok... so you have 2 tables, accounts and characters

accounts has atleast 2 columns called ID and the other called USERNAME

characters has at least 2 columns called account_id and name

is that correct so far?

based on that you could do the following:

SELECT c.name FROM accounts a, characters c WHERE c.account_id = a.id AND username = '{$username}'

that would return any row where column account_id in characters matches the ID in accounts where the username is equal to whatever the $username value is, and only return 1 column called NAME from the characters table.

I probably confused the living crap out of you... but take a look at it... its really much simpler than you might think