Jump to content
Дизайн и модификация IPS Community IPBSkinsBETA
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
TemKa_SD

Фильтр по играм

Recommended Posts

Здравствуйте. Мне необходимо реализовать фильтр по картам, функционал весь готов, осталось вывести правильно сам фильтр.

 

И так, структура БД: http://prntscr.com/llhs1f

 

Мне нужно получить уникальные botid и gamename, так как они дублируются.

 

Получил список уникальных botid: http://prntscr.com/llht3e это основа, по которой должен формироваться фильтр, id чекбоксов будет равен этому полю.

 

Как мне получить имя игры?

 

Т.е должно быть что-то вроде: select gamename from stats_gamelist where botid='' and id='здесь первый попавшийся автоинкримент, чтобы вывести только одно значение';

 

Наверно ничего не понятно....!!!!@@@###$$$

Share this post


Link to post

Предоставляйте код. Нет желания писать по картинке.

Share this post


Link to post

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 by TemKa_SD

Share this post


Link to post

Как вариант

            foreach( \IPS\Db::i('wc3')->select( 'botid, gamename', 'stats_gamelist', NULL, 'botid ASC' ) as $bot )
           {
               static::$cachedBotlist[$bot['botid']] = $bot['gamename'];
           }

  • Upvote 1

Share this post


Link to post

Ого, супер, то что надо думаю. Спасибки )

Share this post


Link to post

Я немного отформитировал имя игры: http://prntscr.com/llid4m

 

static::$cachedBotlist[$bot['botid']] = array_map('trim', explode('#', $bot['gamename']) );

можно как-то удалить ключ 1 из массива? эти данные не нужны просто.

Share this post


Link to post

можно как-то удалить ключ 1 из массива? эти данные не нужны просто.

array_map('trim', explode('#', $bot['gamename']) )[0]

или

current( array_map('trim', explode('#', $bot['gamename']) ) )

 

В этом случае static::$cachedBotlist[$bot['botid']] будет содержать значение первого элемента массива кои является строка.

Share this post


Link to post

Спасибо, работает. Сделал еще массив, так как мне нужны еще данные.

 

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.

Share this post


Link to post
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'];
}
}

  • Upvote 1

Share this post


Link to post

Правильно вывел кол-во игр?

 

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 by TemKa_SD

Share this post


Link to post

А как ключ то вывести? http://prntscr.com/lljfcc

 

И как лучше сделать, botid использовать в виде ключей или данных массива?

Share this post


Link to post

Не отвечайте, работает же )

 

Можно вместо count($bot['id']) писать 1

 

А как ключ то вывести? http://prntscr.com/lljfcc

 

....as $id => $bot}}

И как лучше сделать, botid использовать в виде ключей или данных массива?

 

Как хотите, так и делайте

Share this post


Link to post

Скажите еще вот что, я сделал всё на основе фильтра форумов, добавил data-controller="wc3.front.games.runningGamesFilter" и всё остальное. При нажатии нет обновления контента: https://dev.wc3.info/wc3/runningGames/ ну оно и понятно, наверное нужно через table делать. Какие варианты есть?

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...