i will try it:
The tables:
CREATE TABLE mmobg_relations (
id int(11) NOT NULL default '0',
user_id int(11) NOT NULL default '0',
other_id int(11) NOT NULL default '0',
relation int(11) NOT NULL default '0'
) TYPE=MyISAM;
INSERT INTO mmobg_relations VALUES (0, 1, 2, 5);
INSERT INTO mmobg_relations VALUES (1, 1, 1, 1);
INSERT INTO mmobg_relations VALUES (2, 10, 2, 3);
CREATE TABLE mmobg_systems (
id int(11) NOT NULL auto_increment,
user_id int(11) NOT NULL default '0'
) TYPE=MyISAM;
INSERT INTO mmobg_systems VALUES(1, 2);
INSERT INTO mmobg_systems VALUES(2, 1);
INSERT INTO mmobg_systems VALUES(3, 10);
INSERT INTO mmobg_systems VALUES(4, 3);
"mmobg_systems" is a table with all son-systems of the univers (there are normaly up to 10000 rows with some more fields like coordinates).
Now i want every planet => "SELECT * FROM mmobg_systems"
In addition i want the relation to the son-system owner. The owner of a system is saved as "user_id" in the "mmobg_systems" table.
In the "mmobg_relations" table are the relations between the Users. My ID is 1 and is saved in the php variable "$user[id]".
In mmobg_relations the relation (friendly or hostile) is saved through the two user-ids (user_id and other_id).
For my relation the rows with "user_id"=1 are interesting, because this rows marks the relation to the other users ("other_id").
I tried to collect the informations of the EVERY Planet and the relation to the Planet owner. If i had no relation to the planet owner, the "relation" value may be "0":
$result = mysql_query("
SELECT a.id,a.user_id,b.relation
FROM mmobg_systems as a LEFT JOIN mmobg_relations as b ON a.user_id=b.other_user_id");
But with this query i get wrong results.
If u look in the "mmobg_relations" table, you will see, that there are more then one relation to player 2 (owner of the planet with ID=1). One relation is from User 1 (me) and one Relation is from User 10 (any other User). With the query some lines above i get the wrong result/relation often, because i get the relation from User 10 to User 2, not the relation of User 1 (me) to User 2.
Therefore I tried to use a WHERE:
$result = mysql_query("
SELECT a.id,a.user_id,b.relation
FROM mmobg_systems as a LEFT JOIN mmobg_relations as b ON a.user_id=b.other_user_id
WHERE b.user_id='$user[id]'");
With this query i get a other mistake...
Now i only get the planets with relations to me. For example: I won't get the system ID=4, because i had no relation to USER 3. In this case i want to get an emty relation result.
Summary: The Result i want:
I want every Son-System of the "mmobg_systems" table and I want every relation to the system owner (saved in "mmobg_systems"->"user_id"). The relations are in the "mmobg_relations" table in the format: relation from (field)"user_id" to (field) "other_id". If there is no relation entry to the planet owner, i want to get "relation"=0 in my result.
Again: Thanks for help and sorry for my (very) bad english.