using 2 databases
Moderator: General Moderators
using 2 databases
i have a website im making for a game, and i have 2 databases, one for guilds and one for the users. i was wondering if there would be a way to do what i need like this. i have a field in the user database that is called guild, and either has the guild name or is null. i need it to where that person can login, and be able to go to the guild section of the site and have the guild they are in pop up, so i was wondering if theres a way you can use the guild field in the user database, take the guild name (ex: SLX), and search for the guild SLX in the guild database, find it, and have the user view thier guild's info, rank, ect.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Ok, i read up some on joins and things, but all i read or could find were examples or tutorials on how to match info from 2 tables and display them on a table, matched together. I was wondering if theres a way i can have the guild field in the user table say SLX, and the name field in the guild table with SLX be found, then the user be sent to the Guild Control Panel for SLX members only. Also, i was wondering if i could get some help on the best way to use ranks with this too in the guild, for ranks that can recruit, edit members, and others who cant do either. Im lost on which way to go 
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Why is this in PHP - Code? Moved to Databases.
Queries are allowed to span databases too.
Queries are allowed to span databases too.
Code: Select all
SELECT foo FROM someDatabase.someTable WHERE bar = 1feyd | Please use
so the result is taking the session from the guild the member is in, under the guild field in the user table, and takes that value, which is SLX, but thats where i get lost, and then start to wonder if i even got that right. Ive messed around with php off and on, i know enough to make an... ok site, but im still pretty new to databases and learning as i run into things.
im actually really kinda getting lost on how to do guilds in a database at all.
i need it where someone can be in a guild and go to guild cp and see members, and if their rank in the guild lets them, be able to add new members, or edit members. basically i need them to have to login, go to guild cp, have their guild cp specified for the guild theyre in (EX: SLX), then, say the leader logs in, have the ability to view all members, some guild info, add/remove members, and change their ranks. if anyone has any idea on how to go about this, please help. :/ ive confused myself too far i think...
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Im not exactly getting how do to the query with that, i read a little on the bar =1 thing but dont quite understand. my database is loginphp, the table for a guild would be slx, i think it would be best for each guild to have its own table, but if thats not a good idea, please let me know, the guild i created is SLX, so i have something like thisCode: Select all
$result = mysql_query("SELECT . $_SESSION['Guild'] . FROM loginphp WHERE bar = 1")
or die(mysql_error());
$row = mysql_fetch_array( $result ); //set $row to resultim actually really kinda getting lost on how to do guilds in a database at all.
i need it where someone can be in a guild and go to guild cp and see members, and if their rank in the guild lets them, be able to add new members, or edit members. basically i need them to have to login, go to guild cp, have their guild cp specified for the guild theyre in (EX: SLX), then, say the leader logs in, have the ability to view all members, some guild info, add/remove members, and change their ranks. if anyone has any idea on how to go about this, please help. :/ ive confused myself too far i think...
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
I only read to the code, but I have some pointers for you.
- You shouldn't be dynamically creating tables (for the guilds). Have a table called guilds and add to that when a new guild is created.
- You need to read up on how to build SQL queries. You do not SELECT * FROM databasename. You SELECT * FROM tablename.
- feyd gave you an example WHERE clause, which was bar = 1. This is not an essential part of the query; you won't need it in yours.
If you're trying to fetch guild information you might end up with a query like this:
- You shouldn't be dynamically creating tables (for the guilds). Have a table called guilds and add to that when a new guild is created.
- You need to read up on how to build SQL queries. You do not SELECT * FROM databasename. You SELECT * FROM tablename.
- feyd gave you an example WHERE clause, which was bar = 1. This is not an essential part of the query; you won't need it in yours.
If you're trying to fetch guild information you might end up with a query like this:
Code: Select all
SELECT * FROM `guilds` WHERE `guild_id` = $_SESSION['Guild']loginphp is the table name inside the databse 988_login
i have a guild field for the members to specify what guild they are in.
thats the code im using, but i keep getting this error
"Unknown column 'SLX' in 'where clause"
so what i did was take the query and put it in phpmyadmin
SLX is the name of the sample guild im using. I get the same error, but when i put this in the phpmyadmin
it works, so i was wondering how to make the query in the php code work like the second query i put in phpmyadmin, i tried a few things, some dumb things like putting extra "" in it, which obviously didnt work
i have a guild field for the members to specify what guild they are in.
Code: Select all
<?php
include("configlogin.php");
if($_SESSION['Uname'] == "")
{
echo error();
}
else
{
$result = mysql_query("SELECT * FROM guilds WHERE guild_tag = " . $_SESSION['Guild'] . "") or die(mysql_error());
$row = mysql_fetch_array( $result ); //set $row to result
$enc = $_SESSION['Guild'];
if($row['guild_tag'] == $enc)
{
echo "<center><font color=CCCCCC><b>Welcome to " . $_SESSION['Guild'] . " " . $_SESSION['Uname'] . "!</b></font>";
}
}
function error()
{
echo "<b>You must login to use this feature!</b>";
}
?>"Unknown column 'SLX' in 'where clause"
so what i did was take the query and put it in phpmyadmin
Code: Select all
SELECT * FROM guilds WHERE guild_tag = SLXCode: Select all
SELECT * FROM guilds WHERE guild_tag = "SLX"- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
You need to read up on some fundamental rules of PHP.
In this particular case, you will need to choose one of the following options:
- Use single quotes around the string in your query.
- Use single quotes around your entire query string.
- Leave the $_SESSION variable inside the query string, but surround it with curly brackets (make sure the query string is in double quotes).
- Use the escape character on your nested double quotes.
Search for the page on strings in the PHP manual.
In this particular case, you will need to choose one of the following options:
- Use single quotes around the string in your query.
- Use single quotes around your entire query string.
- Leave the $_SESSION variable inside the query string, but surround it with curly brackets (make sure the query string is in double quotes).
- Use the escape character on your nested double quotes.
Search for the page on strings in the PHP manual.
Code: Select all
<?php
include("configlogin.php");
if($_SESSION['Uname'] == "")
{
echo error();
}
else
{
$result = mysql_query("SELECT * FROM `guilds` WHERE `Tag` = '{$_SESSION['Guild']}'") or die(mysql_error());
$row = mysql_fetch_array( $result ); //set $row to result
$enc = $_SESSION['Guild'];
if($row == $enc)
{
echo "<center><font color=CCCCCC><b>Welcome to " . $_SESSION['Guild'] . " " . $_SESSION['Uname'] . "!</b></font>";
}
}
function error()
{
echo "<b>You must login to use this feature!</b>";
}
?>Code: Select all
echo "<center><font color=CCCCCC><b>Welcome to " . $_SESSION['Guild'] . " " . $_SESSION['Uname'] . "!</b></font>";yep, thanks. i am officially retarded though.
i have a different question now. in the guild table, there is a field i have called members. is there a way to have every members name in one field, then be able to pull out each individual name onto a row? like the members field has cyril, decus, jim, tank, joe in it, id need it put out on the site like
cyril
decus
jim
tank
joe
there is also the field in loginphp table for members called guild, that specifies what guild they are in if the above way cannot work. im starting to hate this i keep getting stumped too easily
i have a different question now. in the guild table, there is a field i have called members. is there a way to have every members name in one field, then be able to pull out each individual name onto a row? like the members field has cyril, decus, jim, tank, joe in it, id need it put out on the site like
cyril
decus
jim
tank
joe
there is also the field in loginphp table for members called guild, that specifies what guild they are in if the above way cannot work. im starting to hate this i keep getting stumped too easily
Code: Select all
CREATE TABLE `guilds`(
guildid INT(11) auto_increment,
guildname VARCHAR(32) NOT NULL,
guildtag VARCHAR(8) NOT NULL,
PRIMARY KEY(`guildid`)
);
CREATE TABLE `users`(
userid INT(11) auto_increment,
username VARCHAR(32) NOT NULL,
userpass VARCHAR(32) NOT NULL,
PRIMARY KEY(`userid`)
);
INSERT INTO guilds (guildid,guildname,guildtag) VALUES
(1,'Guild1', '#1'),
(2,'GuildABC', 'ABC');
INSERT INTO users (userid,username,userpass) VALUES
(1,'Justus', 'xyz'),
(2,'Peter', 'xyz'),
(3,'Bob', 'xyz');Justus(userid=1) and Peter(userid=2) are members of Guild1(guildid=1)
Bob(userid=3) is a member of GuildABC(guildid=2)
All you need to store are the numbers
Justus -> (1,1)
Peter -> (2,1)
Bob -> (3,2)
in a separate table
Code: Select all
CREATE TABLE `guildmembers`(
guildid INT(11) auto_increment,
userid INT(11) auto_increment,
KEY(`guildid`),
KEY(`userid`)
);
INSERT INTO guildmembers (userid,guildid) VALUES
(1, 1),
(2, 1),
(3, 2);