• 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 [Gesior2012][database query]

Shadow Dan

Sh4dowDan
Joined
Jun 5, 2010
Messages
344
Reaction score
88
Location
Poland
I was trying to make query to see value of paw and fur storage so i could show how many points of paw and fur i have.
Paw and fur is key 2500 always and i need to see value of this storage.

Code:
'.$pawandfur[0].'
Code:
        $id = $player->getCustomField("id");
        $pawandfur = $SQL->query("SELECT * FROM `player_storage` WHERE `player_id` = ".$id." AND `key` = `2500`;");
I've been trying this way but nothing.
When i do this:
Code:
        $id = $player->getCustomField("id");
        $pawandfur = $SQL->query("SELECT * FROM `player_storage` WHERE `player_id` = ".$id." AND `key` = `2500`;")->fetch();
There is error:
Code:
Fatal error: Call to a member function fetch() on boolean in *:\****\****\****\characters.php on line 92
92 line is database query.
Still need some help with database queries.
 
Code:
$id = $player->getCustomField("id");
$pawandfur = $SQL->query("SELECT * FROM `player_storage` WHERE `player_id` = ".$id." AND `key` = `2500`;")->fetch();

Clean it, use this for your select:
$SQL it's your struture, and you select tables in your db with a Query.
Then, you can use:

$SQL->query("SELECT * FROM player_storage WHERE player_id = '$id' AND key = '2500'");

This query select a storage key of a player (player_id).

You can convert this select in array or simple object.
Use correct function for this, if you use MySQLi, PDO or MySQL

Example of MySQL Lib:
$objects=mysql_fetch_array($SQL);

If you need see your object value: use print or echo: $objects['your_collum'];


I hope this helps.
 
Last edited:
PHP:
    $id = $player->getID();
    $pawandfur = $SQL->prepare('
        SELECT
            `value`
        FROM
            `player_storage`
        WHERE
            `player_id`=:playerid
        AND
            `key`=2500
    ');

    // Bind the query params
    $pawandfur->bindParam(':playerid', $id, PDO::PARAM_INT);
    $pawandfur->execute();

    // Do we have any results?
    if ($pawandfur->rowCount() > 0) {
        // Define how we want to fetch the results
        $pawandfur->setFetchMode(PDO::FETCH_ASSOC);
        $result = new IteratorIterator($pawandfur);

        foreach ($result as $row) {

            $main_content .= 'Value: '.$row['value'].'';
        }
    }


Try this
 
Oh my gosh, so database query can just select and i need to write a script for converting it into value?

raf Thank you! It is working.
 
Last edited:
Back
Top Bottom