TemKa_SD Posted November 22, 2018 Share Posted November 22, 2018 Здравствуйте. Мне необходимо реализовать фильтр по картам, функционал весь готов, осталось вывести правильно сам фильтр. И так, структура БД: http://prntscr.com/llhs1f Мне нужно получить уникальные botid и gamename, так как они дублируются. Получил список уникальных botid: http://prntscr.com/llht3e это основа, по которой должен формироваться фильтр, id чекбоксов будет равен этому полю. Как мне получить имя игры? Т.е должно быть что-то вроде: select gamename from stats_gamelist where botid='' and id='здесь первый попавшийся автоинкримент, чтобы вывести только одно значение'; Наверно ничего не понятно....!!!!@@@###$$$ Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 Что-то вроде такого наверно: http://prntscr.com/llhyjg Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 Ну да, вот примерно так: http://prntscr.com/lli0qn http://prntscr.com/lli10w Link to comment Share on other sites More sharing options...
newbie Posted November 22, 2018 Share Posted November 22, 2018 Предоставляйте код. Нет желания писать по картинке. Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 (edited) public static function getBotlist() { if( static::$cachedBotlist === NULL ) { foreach( \IPS\Db::i('wc3')->select( 'botid', 'stats_gamelist', NULL, 'botid ASC', array(), NULL, NULL, 1 ) as $bot ) { static::$cachedBotlist[] = $bot = [ 'botid' => $bot, 'gamename' => 'Imya Igry', ]; } } return static::$cachedBotlist; } Я думаю, нужно что-то вроде: 'gamename' => 'Здесь select gamename ->first()',Ну еще мне надо вывести кол-во Игр botid по полю ID наверно и игроков по полю total. И если я прав, везде так фёрст юзать? или надо форич? или я вообще бред несу? Edited November 22, 2018 by TemKa_SD Link to comment Share on other sites More sharing options...
newbie Posted November 22, 2018 Share Posted November 22, 2018 Как вариант foreach( \IPS\Db::i('wc3')->select( 'botid, gamename', 'stats_gamelist', NULL, 'botid ASC' ) as $bot ) { static::$cachedBotlist[$bot['botid']] = $bot['gamename']; } 1 Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 Ого, супер, то что надо думаю. Спасибки ) Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 Я немного отформитировал имя игры: http://prntscr.com/llid4m static::$cachedBotlist[$bot['botid']] = array_map('trim', explode('#', $bot['gamename']) ); можно как-то удалить ключ 1 из массива? эти данные не нужны просто. Link to comment Share on other sites More sharing options...
siv1987 Posted November 22, 2018 Share Posted November 22, 2018 можно как-то удалить ключ 1 из массива? эти данные не нужны просто. array_map('trim', explode('#', $bot['gamename']) )[0]илиcurrent( array_map('trim', explode('#', $bot['gamename']) ) ) В этом случае static::$cachedBotlist[$bot['botid']] будет содержать значение первого элемента массива кои является строка. Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 Спасибо, работает. Сделал еще массив, так как мне нужны еще данные. public static function getBotlist() { if( static::$cachedBotlist === NULL ) { foreach( \IPS\Db::i('wc3')->select( 'id, botid, gamename, totalplayers', 'stats_gamelist', NULL, 'botid ASC' ) as $bot ) { static::$cachedBotlist[$bot['botid']] = [ 'gamename' => current( array_map('trim', explode('#', $bot['gamename']) ) ), 'players' => $bot['totalplayers'] ]; } } return static::$cachedBotlist; } Результат: http://prntscr.com/llil02 Помогите еще с players, сейчас выводит просто поле из выше выбранных игр, мне нужно посчитать ПО ВСЕМ играм http://prntscr.com/llime1 т.е вот обведенные данные нужно сложить и результат положить в один botid. Link to comment Share on other sites More sharing options...
newbie Posted November 22, 2018 Share Posted November 22, 2018 foreach( \IPS\Db::i('wc3')->select( 'id, botid, gamename, totalplayers', 'stats_gamelist', NULL, 'botid ASC' ) as $bot ) { if (!isset(static::$cachedBotlist[$bot['botid']])) { static::$cachedBotlist[$bot['botid']] = [ 'gamename' => current( array_map('trim', explode('#', $bot['gamename']) ) ), 'players' => $bot['totalplayers'] ]; } else { static::$cachedBotlist[$bot['botid']]['players'] += $bot['totalplayers']; } } 1 Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 (edited) Правильно вывел кол-во игр? public static function getBotlist() { if( static::$cachedBotlist === NULL ) { foreach( \IPS\Db::i('wc3')->select( 'id, botid, gamename, totalplayers', 'stats_gamelist', NULL, 'botid ASC' ) as $bot ) { if (!isset(static::$cachedBotlist[$bot['botid']])) { static::$cachedBotlist[$bot['botid']] = [ 'gamename' => current( array_map('trim', explode('#', $bot['gamename']) ) ), 'games' => count($bot['id']), 'players' => $bot['totalplayers'] ]; } else { static::$cachedBotlist[$bot['botid']]['players'] += $bot['totalplayers']; static::$cachedBotlist[$bot['botid']]['games'] += count($bot['id']); } } } return static::$cachedBotlist; } Не отвечайте, работает же ) Edited November 22, 2018 by TemKa_SD Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 А как ключ то вывести? http://prntscr.com/lljfcc И как лучше сделать, botid использовать в виде ключей или данных массива? Link to comment Share on other sites More sharing options...
newbie Posted November 22, 2018 Share Posted November 22, 2018 Не отвечайте, работает же ) Можно вместо count($bot['id']) писать 1 А как ключ то вывести? http://prntscr.com/lljfcc ....as $id => $bot}}И как лучше сделать, botid использовать в виде ключей или данных массива? Как хотите, так и делайте Link to comment Share on other sites More sharing options...
TemKa_SD Posted November 22, 2018 Author Share Posted November 22, 2018 Скажите еще вот что, я сделал всё на основе фильтра форумов, добавил data-controller="wc3.front.games.runningGamesFilter" и всё остальное. При нажатии нет обновления контента: https://dev.wc3.info/wc3/runningGames/ ну оно и понятно, наверное нужно через table делать. Какие варианты есть? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now