Jump to content

HTML, PHP, JSCRIPT, I need help :(

AcidzDesigns

So im helping a friend with some stuff on a site that he is making, and we are trying to pull information from a game server and display it on the site, such as map and player count. Everything is in an array and when we display that information from the array it shows everything, is there a way were i can only display one piece of information from it and use the other bit somewhere else, Codes below

 

Query.php

 

<?php

 
require ('config.php');
require ('class_PQ.php');
 
if (file_exists ($cachefile) && (time () - filemtime ($cachefile) < $cachelifetime)) {
    
    readfile ($cachefile);    
    exit;
    
}
 
$out = '';
 
foreach ($servers as $server) {
    
    $pq = PQ::create(array(
    'ip' => $server['ip'],
    'port' => $server['port'],
    'querytype' => 'halflife',
    'timeout' => 1,
    'retries' => 1,
    ));
    
    $pqinfo = $pq->query(array('info'));
    
    $arr = array ('#name#' => $server ['name'],
                  '#ip#'   => $server ['ip'],
                  '#port#' => $server ['port'],
                  
                  '#map#'        => $pqinfo ['map'],
                  '#players#'    => $pqinfo ['totalplayers'],
                  '#maxplayers#' => $pqinfo ['maxplayers']);
    
    $out .= strtr ($output, $arr);
    
}
 
if ($cachelifetime != 0) {
 
    $fp = fopen ($cachefile, 'w');
    fwrite ($fp, $out);
    fclose ($fp);
    
}
 
echo $out;
 
?>
 

 

Config.php

 

<?php

 
$servers = array (array ('name' => 'Ark PvP Server',
                         'ip' => '89.163.145.206',
                         'port' => 19000),
                  array ('name' => 'DatGamer RP Server',
                         'ip' => '89.163.145.206',
                         'port' => 5000));
 
$cachelifetime = 30;
$cachefile = './cache/servers.html';
 
$output = '<br />#map# #players#/#maxplayers#<br /><br />';
 
?>
 

Html file where the information is shown

 

                       <li><div id="serverstats-loading">Please wait ...<br /></div>

<div id="serverstats-wrapper" style="display: none"></div>
<script type="text/javascript">
   $(document).ready(function(){
       $.post("query.php", {}, 
           function (data) {
               $('#serverstats-wrapper').html (data);
               $('#serverstats-loading').hide();
               $('#serverstats-wrapper').show ();
           });
   });
</script>
</li>

 

Thanks for taking the time to look at this, any help appreciated 

Link to comment
Share on other sites

Link to post
Share on other sites

-Snip-

I would suggest using MySQL instead of writing to a file and also instead of an array put it in MySQL and you can pull it down as an array and use it anytime you want.

00110000 00110001 00110000 00110000 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110001 00110001 00100000 00110000 00110001 00110001 00110001 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110001 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110000 00110001 

Link to comment
Share on other sites

Link to post
Share on other sites

-Snip

To answer your question, you can use

$arrayname['name of value']

and use it like a normal variable.

00110000 00110001 00110000 00110000 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110001 00110001 00100000 00110000 00110001 00110001 00110001 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110001 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110000 00110001 

Link to comment
Share on other sites

Link to post
Share on other sites

I would suggest using MySQL instead of writing to a file and also instead of an array put it in MySQL and you can pull it down as an array and use it anytime you want.

Any idea on how I can do this man, i have no idea on using MySQL, never done it 

Link to comment
Share on other sites

Link to post
Share on other sites

To answer your question, you can use

$arrayname['name of value']

and use it like a normal variable.

where do i put this, my knowledge of php is very small

Link to comment
Share on other sites

Link to post
Share on other sites

where do i put this, my knowledge of php is very small

How are you displaying the content?

00110000 00110001 00110000 00110000 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110001 00110001 00100000 00110000 00110001 00110001 00110001 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110001 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110000 00110001 

Link to comment
Share on other sites

Link to post
Share on other sites

How are you displaying the content?

Like this

 

<li><div id="serverstats-loading">Please wait ...<br /></div>
<div id="serverstats-wrapper" style="display: none"></div>
<script type="text/javascript">
   $(document).ready(function(){
       $.post("query.php", {}, 
           function (data) {
               $('#serverstats-wrapper').html (data);
               $('#serverstats-loading').hide();
               $('#serverstats-wrapper').show ();
           });
   });
</script>
</li>
Link to comment
Share on other sites

Link to post
Share on other sites

 

Like this

 

<li><div id="serverstats-loading">Please wait ...<br /></div>
<div id="serverstats-wrapper" style="display: none"></div>
<script type="text/javascript">
   $(document).ready(function(){
       $.post("query.php", {}, 
           function (data) {
               $('#serverstats-wrapper').html (data);
               $('#serverstats-loading').hide();
               $('#serverstats-wrapper').show ();
           });
   });
</script>
</li>

 

You can forget the JS, save the file as PHP, all of the HTML will load as normal and just echo it like normal (don't forget the PHP start and end tags)

00110000 00110001 00110000 00110000 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110001 00110001 00100000 00110000 00110001 00110001 00110001 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110001 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110000 00110001 

Link to comment
Share on other sites

Link to post
Share on other sites

This is what it looks like on the site 

 

http://prntscr.com/8p9rwj

 

i dont need the second bit there, but i need it in a different location

Example:

<li><div id="serverstats-loading">Please wait ...<br /></div><div id="serverstats-wrapper" style="display: none"></div>         <?PHP               require "yourfile.php";               echo $array_name['array_value_name'];         ?></li>

Save it as .php and the HTML will work fine and you can now put PHP in it

00110000 00110001 00110000 00110000 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110001 00110001 00100000 00110000 00110001 00110001 00110001 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110001 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110000 00110001 

Link to comment
Share on other sites

Link to post
Share on other sites

Example:

<li><div id="serverstats-loading">Please wait ...<br /></div><div id="serverstats-wrapper" style="display: none"></div>         <?PHP               require "yourfile.php";               echo $array_name['array_value_name'];         ?></li>

Save it as .php and the HTML will work fine and you can now put PHP in it

nope, not working, i have this, not sure if its correct

<li><div id="serverstats-loading">Please wait ...<br /></div>    <div id="serverstats-wrapper" style="display: none"></div>         <?PHP		require "config.php";		echo $array_name['Ark PvP Server'];	?></li>
Link to comment
Share on other sites

Link to post
Share on other sites

 

nope, not working, i have this, not sure if its correct

<li><div id="serverstats-loading">Please wait ...<br /></div>    <div id="serverstats-wrapper" style="display: none"></div>         <?PHP		require "config.php";		echo $array_name['Ark PvP Server'];	?></li>

Rename it .php

and you did it wrong change array_name to the array name and the thing in the quotes to the value in the array

So, if this is your array, and you want the IP

  'ip' => $server['ip'],
    'port' => $server['port'],
    'querytype' => 'halflife',
    'timeout' => 1,
    'retries' => 1,
Put IP in that box.
 
Also, change require to the file with the array.

00110000 00110001 00110000 00110000 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110001 00110001 00100000 00110000 00110001 00110001 00110001 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110001 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110000 00110001 

Link to comment
Share on other sites

Link to post
Share on other sites

i have renamed it to .php, and the file with the array is config,php, and what i want from the server is the map and player count

Link to comment
Share on other sites

Link to post
Share on other sites

i have renamed it to .php, and the file with the array is config,php, and what i want from the server is the map and player count

 change array_name to the array name and the thing in the quotes to the value in the array

So, if this is your array, and you want the IP

  'ip' => $server['ip'],
    'port' => $server['port'],
    'querytype' => 'halflife',
    'timeout' => 1,
    'retries' => 1,
Put IP in that box.

00110000 00110001 00110000 00110000 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110001 00110001 00100000 00110000 00110001 00110001 00110001 00110000 00110000 00110001 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110000 00100000 00110000 00110001 00110001 00110000 00110000 00110001 00110000 00110001 00100000 00110000 00110001 00110001 00110000 00110001 00110001 00110000 00110001 

Link to comment
Share on other sites

Link to post
Share on other sites

 

 change array_name to the array name and the thing in the quotes to the value in the array

So, if this is your array, and you want the IP

  'ip' => $server['ip'],
    'port' => $server['port'],
    'querytype' => 'halflife',
    'timeout' => 1,
    'retries' => 1,
Put IP in that box.

 

Nope, still nothing

Link to comment
Share on other sites

Link to post
Share on other sites

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

×