• 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!

Solved Problem with website showing StorageValue "value" as Array

Vikarious

New Member
Joined
Dec 16, 2008
Messages
93
Reaction score
2
I'm trying to show on website the current time a player have defeated a monster using by referrence the "value" of a StorageValue.

But when I do the query, page displays only "Array".

I can't number each iten of the list beacause it should be 'endless', as the player would fight the creature so many times as he/she wishes.

Basically, everytime player defeat the X creature, Storage value X receives + 1.

What I want is to display the "value" from this storage.

Waht I have by now is:

Code:
$wins = $SQL->query("SELECT 'value' FROM `player_storage` WHERE `player_id` = ".$player->getId()." AND `key` = '200006'")->fetch();
	
	
	
	if ($wins > 0 ) {
	
	echo "$wins";
	
	} 
	
	else
	{
	
	echo "You haven't defeated this boss yet.";
	
	}

When I do the query on a chracter that has never defeated, it returns the right message, but if player has defeated the creature at least 1 time, it returns only "Array".

There's any way to do it, without doing each "if ($wins == 1) .... ?

Thanks in advance!!
 
Last edited:
Try this:

PHP:
$wins = mysql_query("SELECT 'value' FROM `player_storage` WHERE `player_id` = ".$player->getId()." AND `key` = '200006'");
if (empty($wins)){
echo "You haven't defeated this boss yet.";
} else {
while($row = MySQL_Fetch_Assoc($wins)){ 

    echo $row['value'];

}}
 
Problem solved by simply using:
Code:
print_r($query['value']+1);
print_r() Shows on screen, arrays in a way humans can understand.
$query['value'] Is the MySql Array I was trying to show on screen.
+1 Due to the query was counting value 0 as 1, then adding +1 will make display 0 as 1, 1 as 2, making the right count.

Just in case anyone wants to find out how to solve this and why I did used each command.

----
This is an example of the full code:
Code:
$query = $SQL->query("SELECT `value` FROM `player_storage` WHERE `player_id` = ".$player->getId()." AND `key` = '2000013'")->fetch();
	
	if ($query > '0' ) {
	
	echo "This player has defeated Macross The Mad <b><u>"; 
	
                    print_r($query['value']+1); 
	
                    echo "</b></u> times.";
	
	}
	
	
	
	
		else
		{
		echo "This  player <b><u>HAVE NOT YET</u></b> defeated Macross The Mad.";
		}

This is the final product to use on my webpage. Hope it may be of use to anyone some day.

- - - Updated - - -

Thank you so much for you reply OT Creator!

Using the script you posted I still get this:

Code:
A PHP Error was encountered

Severity: Warning
 
Message: mysql_fetch_assoc() expects parameter 1 to be resource, array given
 
Filename: insígnias/injection.php
 
Line Number: 30

I tested in order to understand better this stuff. But it seems that only print_r will work as long we work with arrays.

Many many thanks for your help and time anyway. =)
 
Last edited:
PHP:
$wins = mysql_query("SELECT 'value' FROM `player_storage` WHERE `player_id` = ".$player->getId()." AND `key` = '200006'");
if (empty($wins)){
echo "You haven't defeated this boss yet.";
} else {
while($row = mysql_fetch_array($wins)){ 

    echo $row['value'];

}}
My bad, that should be working
 
Back
Top