SA-MP Forums Archive
Query API please help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Query API please help (/showthread.php?tid=320351)



Query API please help - TheArcher - 22.02.2012

Hi, i'm using QueryAPI by waste https://sampforum.blast.hk/showthread.php?tid=104299 . I tried to test it on my local host using WAMP. I started my server on but it restore empty queries on my PHP page. Here's my PHP code.

PHP код:
<?php
require "SampQueryAPI.php";
$query = new SampQueryAPI('localhost''7777');
if(
$query->isOnline())
{
    
$aInformation $query->getInfo();
    
$aServerRules $query->getRules();
    
    
?>
    <b>Informazioni Generali</b>
    <table width="400">
        <tr>
            <td>NomeServer</td>
            <td><?= htmlentities($aInformation['hostname']) ?></td>
        </tr>
        <tr>
            <td>Gamemode</td>
            <td><?= htmlentities($aInformation['gamemode']) ?></td>
        </tr>
        <tr>
            <td>Giocatori</td>
            <td><?= $aInformation['players'?> / <?= $aInformation['maxplayers'?></td>
        </tr>
        <tr>
            <td>Mappa</td>
            <td><?= htmlentities($aInformation['mapname']) ?></td>
        </tr>
        <tr>
            <td>Tempo</td>
            <td><?= $aServerRules['weather'?></td>
        </tr>
        <tr>
            <td>Ora</td>
            <td><?= $aServerRules['worldtime'?></td>
        </tr>
        <tr>
            <td>Versione</td>
            <td><?= $aServerRules['version'?></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><?= $aInformation['password'] ? 'Yes' 'No' ?></td>
        </tr>
    </table>
    <br />
    <b>Giocatori Online</b>
    <?php
    
    $aPlayers 
$query->getDetailedPlayers();
    
    if(!
is_array($aPlayers) || count($aPlayers) == 0)
    {
        echo 
'<br /><i>Nessuno</i>';
    }
    else
    {
        
?>
        <table width="400">
            <tr>
                <td><b>ID Giocatore</b></td>
                <td><b>Nickname</b></td>
                <td><b>Punteggio</b></td>
                <td><b>Ping</b></td>
            </tr>
        <?php
        
foreach($aPlayers as $sValue)
        {
            
?>
            <tr>
                <td><?= $sValue['playerid'?></td>
                <td><?= htmlentities($sValue['nickname']) ?></td>
                <td><?= $sValue['score'?></td>
                <td><?= $sValue['ping'?></td>
            </tr>
            <?php
        
}
    
        echo 
'</table>';
    }
}
else { echo 
'Server offline'; }
?>
Here's the results on my PHP page when i turn the server on.

Код:
General Info
Server Name
Gamemode
Players /
Map
Weather
Time
Version
Password

Players Online
No one



Re: Query API please help - royal_king - 22.02.2012

Try this one -

PHP код:
<?php
require "samp_query.php";
$serverIP "localhost"// if don't work use 127.0.0.1 or 192.168.1.1
$serverPort 7777;
try
{
        
$rQuery = new QueryServer$serverIP$serverPort );
        
$aInformation  $rQuery->GetInfo( );
        
$aServerRules  $rQuery->GetRules( );
        
$aBasicPlayer  $rQuery->GetPlayers( );
        
$aTotalPlayers $rQuery->GetDetailedPlayers( );
        
$rQuery->Close( );
}
catch (
QueryServerException $pError)
{
       echo 
"Oops! Server Is Currently Offline We'll Be Back Soon. Thanks For Waiting :)";
}
if(isset(
$aInformation) && is_array($aInformation)){
?>
    <b>Server Stats/Information.</b>
    <table width="400">
            <tr>
                    <td>NomeServer</td>
                    <td><?php echo htmlentities($aInformation['Hostname']); ?></td>
            </tr>
            <tr>
                    <td>Gamemode</td>
                    <td><?php echo htmlentities($aInformation['Gamemode']); ?></td>
            </tr>
            <tr>
                    <td>Giocatori</td>
                    <td><?php echo $aInformation['Players']; ?> / <?php echo $aInformation['MaxPlayers']; ?></td>
            </tr>
            <tr>
                    <td>Mappa</td>
                    <td><?php echo htmlentities($aInformation['Map']); ?></td>
            </tr>
            <tr>
                    <td>Tempo</td>
                    <td><?php echo $aServerRules['weather']; ?></td>
            </tr>
            <tr>
                    <td>Ora</td>
                    <td><?php echo $aServerRules['worldtime']; ?></td>
            </tr>
            <tr>
                    <td>Versione</td>
                    <td><?php echo $aServerRules['version']; ?></td>
            </tr>
            <tr>
                    <td>Password</td>
                    <td><?php echo $aInformation['Password'] ? 'Yes' 'No'?></td>
            </tr>
             <tr>
                    <td>Web URL</td>
                    <td><?php echo $aInformation['url']; ?></td>
            </tr>
    </table>
    <br />
    <b>Online Players</b>
    <?php
    
if(!is_array($aTotalPlayers) || count($aTotalPlayers) == 0){
            echo 
'<br /><i>Nessuno</i>';
    } else {
    
?>
        <table width="400">
               <tr> 
                <td><b>ID Giocatore</b></td> 
                <td><b>Nickname</b></td> 
                <td><b>Punteggio</b></td> 
                <td><b>Ping</b></td> 
            </tr>
        <?php
        
foreach($aTotalPlayers AS $id => $value){
        
?>
                <tr>
                        <td><?php echo $value['PlayerID']; ?></td>
                        <td><?php echo htmlentities($value['Nickname']); ?></td>
                        <td><?php echo $value['Score']; ?></td>
                        <td><?php echo $value['Ping']; ?></td>
                </tr>
        <?php
        
}
    
        echo 
'</table>';
    }
}
?>



Re: Query API please help - TheArcher - 22.02.2012

Thank you so much royal after 2 days finnaly helped me out. I think you copied from your server that script beacuse the name of the API is different.


Re: Query API please help - royal_king - 02.03.2012

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
Thank you so much royal after 2 days finnaly helped me out. I think you copied from your server that script beacuse the name of the API is different.
It's my pleasure , I already got this script a long back and I know the way it works, I just edited the few names like you want and gave it to you. That's all.


Re: Query API please help - TheArcher - 02.03.2012

Quote:
Originally Posted by royal_king
Посмотреть сообщение
It's my pleasure , I already got this script a long back and I know the way it works, I just edited the few names like you want and gave it to you. That's all.
Yes, and
PHP код:
<td><?php echo $aInformation['url']; ?></td>
i guess it is not supported by the API.


Re: Query API please help - royal_king - 03.03.2012

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
Yes, and
PHP код:
<td><?php echo $aInformation['url']; ?></td>
i guess it is not supported by the API.
Yeah if you see in API code, there is nothing related to fetch the data of URL, so, it won't work.