Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lajavel's avatar

What relation should I use in this case ?

Hi everyone,

This is 3 tables of my database.

SPELLS id; name; is_heal; stat_id; achievement_lvl

SPELL_DETAILS spell_id; lvl; damage_min; damage_max;

USER_SPELLS user_id; spell_id; lvl

USERS id; .....; ....

I was wondering how to get the minimum damage of a spell according to the user spell lvl .. Using the Spell and User classes. Can anyone help me ?

0 likes
8 replies
willvincent's avatar

I think you've overcomplicating things by separating 'spell details' into its own table, considering that is simply the min/max damage values. Instead just include those on the spell directly, and as a user levels up, change which spell id's are associated with that user.

Not only will that be easier to query, but it's a considerably easier data model to maintain.

Also, just for future reference, it's somewhat unrealistic to expect an immediate response to any and every question in the forum at any time of day, based on the times shown of your original post and sadface followup, you didn't even wait a full hour for anyone to respond... and along with that, your original post is a bit vague, the more clearly you ask your question the more quickly you'll generally receive answers.

Lajavel's avatar

Yeah sorry if i'm not clear. But the problem is that the min and max value are increased according to the spell lvl , so you think the spell_details table is useless ?

martinbean's avatar

@Lajavel Please don’t keep re-posting in your own threads just because no one’s replied after an hour.

With regards to your schema, what’s the difference between the lvl column in your spells_details table, and the lvl column in your user_spells table?

Lajavel's avatar

The "lvl" column in my user_spells table, is the vl of the spell owned by the user, a user can increment the level to each of his spells (max lvl 6).

The "lvl" column in my spells_details allows to know the min and max damage for the spell lvl. (And some other things like the cost in mana etc..)

martinbean's avatar

The "lvl" column in my spells_details allows to know the min and max damage for the spell lvl

I don’t understand. What is a spell level? Doesn’t a user have a spell and “level up”? Why does a spell itself have a level?

Lajavel's avatar

For example :

in SPELL_DETAILS we find the spell "magic arrow", and we know in "SPELL_DETAILS", that the lvl 1 of magic arrow will deals 13 to 16 damage, the lvl 2 will deal 16 to 18 damage etc...

and in USER_SPELLS, if the user has increased the spell "magic arrow" to level 2, thanks to the "SPELL_DETAILS" table we'll know how much deals the lvl 2 of the spell "magic arrow".

I'm sorry if my english is terrible...

martinbean's avatar

@Lajavel Personally, instead of having “min” and “max”, I’d just have a table that has the level and an “upper” limit. What would happen if you added a row for levels 1 to 10, and then another for 12 to 20? What happens if a user was level 11?

Please or to participate in this conversation.