• 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 [PHP] Check if CID exists

atyll

Member
Joined
Dec 30, 2008
Messages
380
Reaction score
16
Hello

I would like to make a script for my website to display whether a player have completed Annihilator Quest (CID: 100), however, I am a bit lost.

What I've come up with so far is:

Code:
<?php
$data = mysql_query("SELECT * FROM player_storage WHERE key = 100") 
or die(mysql_error()); 

$info = mysql_fetch_array( $data ); 

$data2 = mysql_query("SELECT name FROM player_storage WHERE id = ".$info['player_id']." ") 
or die(mysql_error()); 

$info2 = mysql_fetch_array( $data2 );  

?>

However, this gives a SQL syntax error and also I don't know how to display whether the player completed Annihilator or NOT.
Anybody able to help?

Using Nicaw ACC for Avesta
 
Last edited:
Solution
PHP:
 <?php
    $quests = array(
         'QuestName' => 100,
         'QuestName2' => 200 //QuestName => storage_key
    );

    $q = mysql_query("SELECT `key` FROM `player_storage` WHERE `player_id` =  '".$player->attrs['id']."' AND `key` IN(" . implode(',',$quests) . ")");

    $matches = array();
    while($row = mysql_fetch_object($q))
        $matches[] = $row->key;

    //.......

    foreach($quests as $name => $key) {
        // this is where u output ur quests 
        if(in_array($key, $matches)) {
            //quest done
        } else {
            // no entries found on this quest
        }
    }
?>

untested, also not sure if u must check if storage VALUE = 1 or some shit
PHP:
<?php
$data = mysql_query("SELECT * FROM player_storage WHERE key = 100") 
or die(mysql_error()); 

$info = mysql_fetch_array( $data ); 

$data2 = mysql_query('SELECT name FROM players WHERE id = '.$info['player_id']) 
or die(mysql_error()); 

$info2 = mysql_fetch_array( $data2 );  

?>

That should fix your syntax error but
 
Last edited:
I think what this is the right syntax, this is a example..

PHP:
$result = mysql_query("SELECT * FROM player_storage"); 

	while($info = mysql_fetch_array($result))
	{
		if($info['key'] == 100)
			echo $info['player_id'].'<br>';
		else
			die("key not found..");
	}
 
Last edited:
Tried this

PHP:
		<?php
$GetPlayerID = $player->attrs['id'];

$result = mysql_query("SELECT * FROM `player_storage`"); 

    while($info = mysql_fetch_array($result))
    {
        if($info['key'] == 100 && $info['player_id'] == $GetPlayerID)
		// If player completed the quest, display result
            echo 'This player completed annihilator.';
        else
            echo("This player have NOT completed annihilator!");
    }  

?>

It display, that player have NOT completed the quest millions of times... but the player actually have ;P what's wrong?


@EDIT

This displays the correct result when the player have completed the quest, however, it doesnt display anything when the player have NOT.

PHP:
	<?php
$GetPlayerID = $player->attrs['id'];

$result = mysql_query("SELECT * FROM `player_storage` WHERE `player_id` =$GetPlayerID AND `key` =100"); 

    while($info = mysql_fetch_array($result))
    {
        if($info['key'] == 100 && $info['player_id'] == $GetPlayerID) 
			{
		// If player completed the quest, display result
            echo 'This player completed annihilator.';
			} 
			else 
			{
			die("QUEST NOT COMPLETED!");
			}
    }  

?>

Help please?
 
Last edited:
well I believe that mysql_fetch_array($result) would return a boolean would it not? in the case that you are using it, so that when it checks for a key and player id it doesn't find it, but it's repeating because you are using while which is going to give you the response for every storage value in the database because of the query you are using, use this query and branch from there.

PHP:
$result = mysql_query("SELECT * FROM `player_storage` WHERE `player_id` =  '".$GetPlayerID."' AND `key` = '100'");
 
Tried that, works :)

PHP:
<?php
$GetPlayerID = $player->attrs['id']; // loads player ID

$result = mysql_query("SELECT * FROM `player_storage` WHERE `player_id` =  '".$GetPlayerID."' AND `key` = '100'");

$info = mysql_fetch_array($result);
    
        if($info['key'] == 100 && $info['player_id'] == $GetPlayerID) 
			{
		// If player completed the quest, display result
            echo 'This player completed annihilator.';
			} 
			else 
			{
			die("QUEST NOT COMPLETED!");
			}
      

?>

I am planning to check on my website for various quests, don't wanna rewrite this code so many times, how can I implement it to repeat it in much shorter way for different "key" value?
 
Last edited:
Try this:
PHP:
<?php
    $GetPlayerID = $player->attrs['id']; // loads player ID
    $result = mysql_query("SELECT * FROM `player_storage` WHERE `player_id` =  '".$GetPlayerID."' AND `key` = '100'");

    $found = false;
    while($info = mysql_fetch_array($result))
    {
        echo 'This player completed annihilator.';
        $found = true;  
    }  

    if(!found)
        die("QUEST NOT COMPLETED!");
?>
 
why's it in a loop?
PHP:
 <?php
    $GetPlayerID = $player->attrs['id']; // loads player ID
    $q = mysql_query("SELECT * FROM `player_storage` WHERE `player_id` =  '".$GetPlayerID."' AND `key` = '100'");

    if(mysql_num_rows($q) > 0)
        echo 'This player completed annihilator.';
    else
        die("QUEST NOT COMPLETED!");
?>
 
Tried that, works :)

PHP:
<?php
$GetPlayerID = $player->attrs['id']; // loads player ID

$result = mysql_query("SELECT * FROM `player_storage` WHERE `player_id` =  '".$GetPlayerID."' AND `key` = '100'");

$info = mysql_fetch_array($result);
    
        if($info['key'] == 100 && $info['player_id'] == $GetPlayerID) 
			{
		// If player completed the quest, display result
            echo 'This player completed annihilator.';
			} 
			else 
			{
			die("QUEST NOT COMPLETED!");
			}
      

?>

I am planning to check on my website for various quests, don't wanna rewrite this code so many times, how can I implement it to repeat it in much shorter way for different "key" value?
 
Ughm, I dont know anything about Nicaw but both gesior and Modern have storage values in their POT just like your script used $player->attrs['id'] you can always check to see if there is a current function that checks storage?

but best way to do it if not is to create a function in the POT that will do basically what your current query does, so you just call the function but in the parameters of the function you have the key value

example

playerStorage(keyvalue)
 
Last edited:
PHP:
 <?php
    $quests = array(
         'QuestName' => 100,
         'QuestName2' => 200 //QuestName => storage_key
    );

    $q = mysql_query("SELECT `key` FROM `player_storage` WHERE `player_id` =  '".$player->attrs['id']."' AND `key` IN(" . implode(',',$quests) . ")");

    $matches = array();
    while($row = mysql_fetch_object($q))
        $matches[] = $row->key;

    //.......

    foreach($quests as $name => $key) {
        // this is where u output ur quests 
        if(in_array($key, $matches)) {
            //quest done
        } else {
            // no entries found on this quest
        }
    }
?>

untested, also not sure if u must check if storage VALUE = 1 or some shit
 
Solution
Back
Top