Advertisement
jDanek

WIP - rpg sql query

Nov 30th, 2022 (edited)
991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. <?php
  2.  
  3. $sql = "SELECT ch.*,
  4.        CONCAT('[', IF(chat.character_id IS NULL, '', GROUP_CONCAT(DISTINCT CONCAT_WS('','{\"id\":\"', ab.id, '\", \"name\":\"', ab.name, '\", \"level\":\"', chab.level, '\", \"desc\":\"', ab.description,'\", \"type\":\"', abt.name, '\"}'))), ']') as _abilities,
  5.        CONCAT('[', IF(chat.character_id IS NULL, '', GROUP_CONCAT(DISTINCT CONCAT_WS('','{\"id\":\"', at.id, '\", \"name\":\"', at.name, '\", \"val\":\"', chat.val, '\", \"max_val\":\"', chat.max_val, '\", \"desc\":\"', at.description,'\"}'))), ']') as _attributes,
  6.        GROUP_CONCAT(DISTINCT CONCAT_WS('','{\"id\":\"', gu.id, '\", \"name\":\"', gu.name, '\"}')) as _guild,
  7.        GROUP_CONCAT(DISTINCT CONCAT_WS('','{\"id\":\"', ra.id, '\", \"name\":\"', ra.name, '\", \"gender\":\"', ra.gender, '\"}')) as _race,
  8.        GROUP_CONCAT(DISTINCT CONCAT_WS('','{\"id\":\"', re.id, '\", \"name\":\"', re.name, '\"}')) as _region
  9.        FROM sunlight_rpg_character ch
  10.        LEFT JOIN sunlight_rpg_character_ability chab ON chab.character_id = ch.id
  11.        LEFT JOIN sunlight_rpg_ability ab ON chab.ability_id = ab.id
  12.        LEFT JOIN sunlight_rpg_ability_type abt ON ab.type = abt.id
  13.        LEFT JOIN sunlight_rpg_character_attribute chat ON chat.character_id = ch.id
  14.        LEFT JOIN sunlight_rpg_attribute at ON chat.attribute_id = at.id
  15.        LEFT JOIN sunlight_rpg_guild gu ON ch.guild_id = gu.id
  16.        LEFT JOIN sunlight_rpg_race ra ON ch.race_id = ra.id
  17.        LEFT JOIN sunlight_rpg_region re ON ch.region_id = re.id
  18.        WHERE " . $where . " GROUP BY ch.id";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement