Jump to content

Table joining


Lv-Kris

Recommended Posts

Ok, hers the situation:

Here are some of mine tables: user data, user_weapons, game_weapons

The idea is to store only the weapon_id and amount of those user has in the user_weapons table. Then its linked to game_weapons, where we get weapon details from.

Well i need a little help on joining them all together...

For example user attacks other user with his weapon, he chooses the weapon id and the amount of damage depends on the weapon stats stored in game_weapons table.

I am willing to do this because of easier modifying later ;D Hope You got the idea.

Kris

Link to comment
Share on other sites

SELECT *
FROM user_data
JOIN user_weapons ON (user_data.user_id = user_weapons.user_id)
JOIN game_weapons ON (user_weapons.weapon_id = game_weapons.weapon_id)
WHERE user_id = $user_id

 

That's the basic structure for a join.

Link to comment
Share on other sites

that measn you have more than one row as a result and each row is an array, you have to make a loop  to echo each row

 


for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$row[$i] = mysql_fetch_assoc($result);
print_r($row[$i]);
}

 

result being the result of your query (wich is what gives you Resource id #29)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.