• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Zapytanie SQL

Pokeball

New Member
Joined
Dec 14, 2009
Messages
51
Reaction score
0
Witam potrzebuje zapytanie dosyć skomplikowane zapytanie SQL

Ma sprawdzać ilość itemków w depo , na postaci i w domku jeśli np ktoś ma więcej niż 10 softów to usuwa mu all softy


Pozdrawiam
 
np.
Code:
SELECT * FROM `player_items` WHERE `itemtype` = '2160' and `count` > 10
Code:
SELECT * FROM `player_depotitems` WHERE `itemtype` = '2160' and `count` > 10
 
np.
Code:
SELECT * FROM `player_items` WHERE `itemtype` = '2160' and `count` > 10
Code:
SELECT * FROM `player_depotitems` WHERE `itemtype` = '2160' and `count` > 10

Przeciez softy nie sa 'stackable' (count = 1).
 
PHP:
SELECT COUNT(`itemtype`) FROM `player_items` WHERE `itemtype` = 'SOFTY' AND `player_id` = 'ID PLAYERA CO GO SE CHCEM SPRAWDZIC CZY MA DUZO BUTOW CZY TEZ NIE I W OGOLE CZY TRZA USUNAC MU OK?';
Potem fetch, a nastepnie jesli $fetch[0] >= jakas liczba to
PHP:
DELETE FROM `player_items` WHERE `itemtype` = 'SOFTY' AND `player_id` = 'ID TEGO PLAYERA CO GO SPRAWDZALES BO W OGOLE ON MA BUTY OSZUKANE';
cos takiego ok?
 
Nemaneth no jest ok tylko jakoś nie wiem może w php czy coś żeby sam all playerów sprawdził
 
PHP:
SELECT `id` FROM `players` WHERE `deleted` = 0;
fetch, loop.

Masz, nawet Ci zrobilem.
PHP:
<?php
	define('ITEM_ID', 2006);
	define('MAX_COUNT', 20);
	$players = array();
	$sql = new MySQLi('localhost', 'root', 'pass', 'baza');
	$ids = $sql->query("SELECT `players`.`id` FROM `players` #WHERE `players`.`deleted` = '0';");
	
	while($id = $ids->fetch_row())
	{
		if($fetch = $sql->query("SELECT COUNT(`player_items`.`itemtype`) FROM `player_items` WHERE `player_items`.`player_id` = '{$id[0]}' AND `player_items`.`itemtype` = '".ITEM_ID."';")->fetch_row())
			$players[$id[0]] = $fetch[0];
	}
	
	foreach($players as $id => $count)
		if($count >= MAX_COUNT)
		{
			echo "Deleting {$count} item(s) (".ITEM_ID.") from player {$id}.<br />";
			$sql->query("DELETE FROM `player_items` WHERE `player_items`.`itemtype` = '".ITEM_ID."' AND `player_items`.`player_id` = '{$id}';");
		}

	unset($sql);
?>

Usun hash (#) zeby pobieralo tylko od nieusunietych graczy.
 
Last edited:
Back
Top