Jump to content
  • 0

TOP RITCHEST STATS PROBLEM


Question

Recommended Posts

  • 0
Posted

One more problem with statistics. Wanna make top ritchest players. But Admin account is added too. How could i change it so that admin wont be shown?

$statement = "SELECT owner_id, count FROM items WHERE item_id = 57 AND count > 10 ORDER by count DESC LIMIT 10 ";
				$statement = $pdo->prepare($statement);
				$statement->execute();
				while($row = $statement->fetch()) {
						$statement2 = "SELECT char_name, accesslevel FROM characters WHERE obj_id = '".$row['owner_id']."' AND accesslevel <= 0";
						$statement2 = $pdo->prepare($statement2);
						$statement2->execute();
						$count++;
						$number = floor($row['count'] / 1000000);
						while($row = $statement2->fetch()) {
								
								$name =	$row['char_name'];
									
						}
							echo
							"
								<tr>
									<td class='number'>".$count."</td>
									<td class='name'>".$name."</td>
									<td class='value'>".$number."kk</td>
								</tr>
							";
						
					}

 

  • 0
Posted
1 minute ago, admirolas3 said:

Problem is that acceslevel is in different table. If it would be in same than ok. Those two tables has only one same cell, that is owner_id

oh rly, then u can connect two tables or just check by owener id. example:

item_id = 57 AND count > 10 AND owner_id=1484984

  • 0
Posted
3 minutes ago, wongerlt said:

oh rly, then u can connect two tables or just check by owener id. example:

item_id = 57 AND count > 10 AND owner_id=1484984

I dont imagine how to do it. At first statement it gets 10 top numbers with an  player ids. Than with that id it checks for a player name and accesslevel in other statement. So if it founds that admin account was added, the top 10 becomes only 9. Because at first statemnet it takes 10 lines with an admin account..

  • 0
Posted
2 minutes ago, .Elfocrash said:

Your query is SQL injectable. Parameterise the parameters properly or else you expose your whole db.

Could you give an example?

  • 0
Posted
9 minutes ago, admirolas3 said:

Problem is that acceslevel is in different table. If it would be in same than ok. Those two tables has only one same cell, that is owner_id

 

google about sql left join

  • 0
Posted (edited)
SELECT i.owner_id, i.count from items as i
inner join characters c on c.obj_Id = i.owner_id 
WHERE i.item_id = 57 and i.count > 10 and c.accesslevel = 0
ORDER BY count DESC limit 10

 

Edited by .Elfocrash
  • 0
Posted
3 minutes ago, .Elfocrash said:

LEFT JOIN! HAHAHHAHAHAHAHAHAAA

 

Here is the query you need.


SELECT owner_id, count from items as i
inner join characters c on c.obj_Id = i.owner_id 
WHERE i.item_id = 57 and i.count > 10 and c.accesslevel = 0
ORDER BY count DESC limit 10

However read about prepared statements here: https://www.w3schools.com/php/php_mysql_prepared_statements.asp

 Could you add "char_name" in this query?

  • 0
Posted (edited)
2 minutes ago, admirolas3 said:

 Could you add "char_name" in this query?

 

Ofc you can, because you joined to the characters table so you can do c.* or c.char_name to get any column or a specific column from the table.

SELECT i.owner_id, c.char_name, i.count from items as i
inner join characters c on c.obj_Id = i.owner_id 
WHERE i.item_id = 57 and i.count > 10 and c.accesslevel = 0
ORDER BY count DESC limit 10
Edited by .Elfocrash
  • 0
Posted (edited)
9 minutes ago, .Elfocrash said:

 

Ofc you can, because you joined to the characters table so you can do c.* or c.char_name to get any column or a specific column from the table.


SELECT i.owner_id, c.char_name, i.count from items as i
inner join characters c on c.obj_Id = i.owner_id 
WHERE i.item_id = 57 and i.count > 10 and c.accesslevel = 0
ORDER BY count DESC limit 10

 

Edited by admirolas3
emty
  • 0
Posted
try {
				$pdo = new PDO("mysql:host=127.0.0.1; dbname=l2j", 'root', '');
				$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				$pdo->query("SET NAMES 'utf8'");
			}
			catch(PDOException  $e) {
				echo "Connection failed: " . $e->getMessage();
		  }

$statement = "SELECT i.owner_id, c.char_name, i.count from items as i inner join characters c on c.obj_Id = i.owner_id WHERE i.item_id = 57 and i.count > 10 and c.accesslevel = 0 ORDER BY count DESC limit 10";
				$statement = $pdo->prepare($statement);
				$statement->execute();
				
				echo "<table style='width: 100%' cellpadding='2'>
						<tr>
							<td colspan='3' style='height: 24px' valign='top'><a href='e107_plugins/l2top/l2top.php?show=4'>Top ritchest players</a></td>
						</tr>
					";
				
				while($row = $statement->fetch()) {
						$count++;
						$number = floor($row['count'] / 1000000);
							echo
							"
								<tr>
									<td class='number'>".$count."</td>
									<td class='name'>".$row['char_name']."</td>
									<td class='value'>".$number."kk</td>
								</tr>
							";
						
					}

 

  • 0
Posted
1 minute ago, admirolas3 said:

The whole code looks like that. Works like a charm. Thanks. What you think, everything looks ok?

Yeap, that's all you need.

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


  • Posts

    • Update M54: Global HP/MP/CP consumable handling expanded beyond combat-only usage. Offensive mage idle recovery with learned skill Battle Heal. Spellhowler/Storm Screamer prioritizes Hurricane, using Vampiric Claw mostly below 90% HP. Major structural refactor initialized: Added category/class organization such as Archer, Dagger, Tank, Mage, Healer, Support and Specialized class files. Further structural cleanup. Extracted combat memory/state and more class-policy logic from the main controller. Added global stuck/inactivity watchdog for bots blocked by terrain/geodata. Added unreachable dropped ground-item timeout/temporary blacklist. Reworked Necromancer/Soultaker PvP: Dominator level 78+ maintains learned Arcane Power toggle on. Overlord/Dominator level 44+ maintains learned Soul Guard toggle automatically. Stability/scalability update: Bot controller ticks staggered instead of all starting in the same phase: Same 350 ms update rate retained Reduces simultaneous AI workload bursts. Removed the old manual aggressive-monster EVT_AGGRESSION bridge. Phantoms now use native Lucera setActive() behavior so monsters aggro them naturally. Reduced unnecessary NPC scans and native AI event pressure. Added saved-bot equipment overrides using a separate database table:         lucera_autobots_items Existing lucera_autobots remains the main saved-bot identity/state table. Equipment rows are linked to saved bots through bot_id. Added optional convenience view to show bot name together with equipment overrides:         lucera_autobots_items_view Added editable equipment slots in columns: Weapon Shield Helmet Chest Legs Gloves Boots Necklace Left/Right Earrings Left/Right Rings Equipment override values: 0 = use normal class/level profile item -1 = force slot empty >0 = equip that Item ID Custom equipment works only for saved database bots. Default class/level equipment profiles remain unchanged. Supports custom equipment from No Grade to S Grade, regardless of the bot's current level. Added validation for invalid item IDs and incompatible equipment slots. Added handling for: Two-handed weapons vs shields Full-body armor vs separate leggings Added all-grade Soulshots and Spiritshots to bot inventory/replenishment so custom lower-grade weapons still use the correct shots. Mage profiles that already use Blessed Spiritshots keep that behavior with all relevant grades available. First save the bot normally so it exists in table:         lucera_autobots Then open:         lucera_autobots_items Find the row with the same bot_id and edit only the equipment slots you want. Example: weapon_id = 6608 shield_id = -1 helmet_id = 0 chest_id = 0 legs_id = 0 gloves_id = 0 boots_id = 0 This means: weapon_id 6608 → custom weapon shield_id -1 → no shield all 0 values → keep normal default profile equipment After editing the DB, despawn and respawn the saved bot so M54 reloads its equipment overrides. Do not edit bot_id. Use it only to identify which saved bot the equipment row belongs to.   DOWNLOAD
    • It will be multi client so it will detect the client from the files and adapt the packets and asset loading. I am aiming for C4 and H5 after IL
    • this is just to simplify your life, time, and can be done for free by yourself just watch some tutorials, in case you don't wanna waste time check it out!   https://l2getwork.art   https://l2getwork.art/showcase.html  
    • Good job! Any chance for it to be downgradeable or at least compatible with older chronicles?
    • Fermata now runs in a web browser too. Try it here: https://web.fermata.gg/    
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..