tables in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Ok here it is from this code:

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
$cyts->connect("xxxxxxxxxx", 51234, xxxx) or print "Cannot connect to server.";
$cyts->login("xxxxxxxx", "xxxxx");
$list = $cyts->info_channelList();
$chanUsers = $cyts->info_channelUser($channel["id"]);
print_r($list);
print_r($chanUsers);
?>

Code: Select all

Array ( [0] => Array ( [0] => 1 12 -1 0 25 "-iOC- Clan TS Server" 24 0 "General Gameplay/Discussion" [1] => 1 [2] => 12 [3] => -1 [4] => 0 [5] => 25 [6] => -iOC- Clan TS Server [7] => 24 [8] => 0 [9] => General Gameplay/Discussion [unparsed] => 1 12 -1 0 25 "-iOC- Clan TS Server" 24 0 "General Gameplay/Discussion" [id] => 1 [codec] => 12 [parent] => -1 [order] => 0 [maxusers] => 25 [name] => -iOC- Clan TS Server [flags] => 24 [password] => 0 [topic] => General Gameplay/Discussion ) [1] => Array ( [0] => 2 12 -1 3200 25 "War Room" 8 0 "" [1] => 2 [2] => 12 [3] => -1 [4] => 3200 [5] => 25 [6] => War Room [7] => 8 [8] => 0 [9] => [unparsed] => 2 12 -1 3200 25 "War Room" 8 0 "" [id] => 2 [codec] => 12 [parent] => -1 [order] => 3200 [maxusers] => 25 [name] => War Room [flags] => 8 [password] => 0 [topic] => ) [2] => Array ( [0] => 3 12 2 3200 25 "Practice" 0 0 "Squad Practice" [1] => 3 [2] => 12 [3] => 2 [4] => 3200 [5] => 25 [6] => Practice [7] => 0 [8] => 0 [9] => Squad Practice [unparsed] => 3 12 2 3200 25 "Practice" 0 0 "Squad Practice" [id] => 3 [codec] => 12 [parent] => 2 [order] => 3200 [maxusers] => 25 [name] => Practice [flags] => 0 [password] => 0 [topic] => Squad Practice ) [3] => Array ( [0] => 4 12 2 3200 25 "Tourny" 0 0 "Squad Domination" [1] => 4 [2] => 12 [3] => 2 [4] => 3200 [5] => 25 [6] => Tourny [7] => 0 [8] => 0 [9] => Squad Domination [unparsed] => 4 12 2 3200 25 "Tourny" 0 0 "Squad Domination" [id] => 4 [codec] => 12 [parent] => 2 [order] => 3200 [maxusers] => 25 [name] => Tourny [flags] => 0 [password] => 0 [topic] => Squad Domination ) [4] => Array ( [0] => 5 12 2 3200 25 "C&C Generals" 0 0 "" [1] => 5 [2] => 12 [3] => 2 [4] => 3200 [5] => 25 [6] => C&C Generals [7] => 0 [8] => 0 [9] => [unparsed] => 5 12 2 3200 25 "C&C Generals" 0 0 "" [id] => 5 [codec] => 12 [parent] => 2 [order] => 3200 [maxusers] => 25 [name] => C&C Generals [flags] => 0 [password] => 0 [topic] => ) [5] => Array ( [0] => 6 12 2 3200 25 "Battlefield 1942" 0 0 "" [1] => 6 [2] => 12 [3] => 2 [4] => 3200 [5] => 25 [6] => Battlefield 1942 [7] => 0 [8] => 0 [9] => [unparsed] => 6 12 2 3200 25 "Battlefield 1942" 0 0 "" [id] => 6 [codec] => 12 [parent] => 2 [order] => 3200 [maxusers] => 25 [name] => Battlefield 1942 [flags] => 0 [password] => 0 [topic] => ) [6] => Array ( [0] => 7 12 2 3200 25 "Lock-On Modern Air Combat" 0 0 "Combat Flight Simulators" [1] => 7 [2] => 12 [3] => 2 [4] => 3200 [5] => 25 [6] => Lock-On Modern Air Combat [7] => 0 [8] => 0 [9] => Combat Flight Simulators [unparsed] => 7 12 2 3200 25 "Lock-On Modern Air Combat" 0 0 "Combat Flight Simulators" [id] => 7 [codec] => 12 [parent] => 2 [order] => 3200 [maxusers] => 25 [name] => Lock-On Modern Air Combat [flags] => 0 [password] => 0 [topic] => Combat Flight Simulators ) [7] => Array ( [0] => 8 12 2 3200 25 "JOTR:" 0 0 "" [1] => 8 [2] => 12 [3] => 2 [4] => 3200 [5] => 25 [6] => JOTR: [7] => 0 [8] => 0 [9] => [unparsed] => 8 12 2 3200 25 "JOTR:" 0 0 "" [id] => 8 [codec] => 12 [parent] => 2 [order] => 3200 [maxusers] => 25 [name] => JOTR: [flags] => 0 [password] => 0 [topic] => ) )

:x I'm lost
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

What's the output for the following snippet?

Code: Select all

<?php
$list = $cyts->info_channelList();

for($i=0;$i<count($list);$i++){
  $chanUsers = $cyts->info_channelUser($list[$i]["id"]);
  print_r($chanUsers);
}
?>
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

It ouputs this array when 1 person is on:

Code: Select all

Array ( [0] => Array ( [0] => 1 1 286 8358 7 938 0 49 299 194 1 5 0 "xx.xxx.xxx.xxx" "-iOC-Jeeep" "Jeeep" [1] => 1 [2] => 1 [3] => 286 [4] => 8358 [5] => 7 [6] => 938 [7] => 0 [8] => 49 [9] => 299 [10] => 194 [11] => 1 [12] => 5 [13] => 0 [14] => xx.xxx.xxx.xxx[15] => -iOC-Jeeep [16] => Jeeep [unparsed] => 1 1 286 8358 7 938 0 49 299 194 1 5 0 "xx.xxx.xxx.xxx" "-iOC-Jeeep" "Jeeep" [p_id] => 1 [c_id] => 1 [ps] => 286 [bs] => 8358 [pr] => 7 [br] => 938 [pl] => 0 [ping] => 49 [logintime] => 299 [idletime] => 194 [cprivs] => 1 [pprivs] => 5 [pflags] => 0 [ip] => xx.xxx.xxx.xxx [nick] => -iOC-Jeeep [loginname] => Jeeep ) ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( )
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

Code: Select all

<?php
$list = $cyts->info_channelList();

for($i=0;$i<count($list);$i++){
  $chanUsers = $cyts->info_channelUser($list[$i]["id"]);
  print($chanUsers['loginname'].", ");
}
?>
This should output all the names currently on.

But something isn't quite right yet since $list obviously held more elements than info_channeluser could provide...
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

That above outputs this

Code: Select all

, , , , , , , ,
I'm looking at the implode function and this is what I have:

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$cyts->connect("xxx.xx.xxx.xx", 51234, xxxx) or die ("Unable to connect to TeamSpeak-server");
$cyts->login("admin", "pass");
header("Content-type: image/png");
    $bg = "teamspeakimg.png";
    $im = @ImageCreateFromPNG($bg);
 
    $width =1;
    $font  = 2;
    $fonta  = 3;
    $black = imagecolorallocate($im, 255, 255, 255); 
$users = $cyts->admin_dbUserList(); 
$srvinfo = $cyts->info_serverInfo();
$playerlist = $cyts->info_playerNameList( );
$tsusers = $cyts->info_playerList();
for($i=0;$i<count($list);$i++){
  $chanUsers = $cyts->info_channelUser($list[$i]["id"]);
 print_r($chanUsers['nick']); 
$chanUsers[nick]= array("[nick]");
$comma_separated = implode(",", $chanUsers);

}

imagestring($im, 2, 5, 5, $srvinfo["server_currentusers"] , $black);
imagestring($im, 2, 20, 5,"users online", $black);
imagestring($im, 2, 5, 15,$srvinfo["server_name"]  , $black);
imagestring($im, 2, 40, 15,"Server" , $black);
imagestring($im, 2, 5, 25,$srvinfo["server_uptime"]  , $black);
imagestring($im, 2, 50, 25,"seconds up", $black);
imagestring($im, 2, 5, 35,$srvinfo["server_currentchannels"]  , $black);
imagestring($im, 2, 17, 35,"Channels", $black);
imagestring($im, 2, 5, 45, $comma_separated  , $black);


    imagePNG($im);
    ImageDestroy;  
?>
But as you can see it doesnt yeild anything http://jeejee2.100webspace.net/servercount.php
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

jeeep wrote:That above outputs this

Code: Select all

, , , , , , , ,
I'm looking at the implode function and this is what I have:

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$cyts->connect("xxx.xx.xxx.xx", 51234, xxxx) or die ("Unable to connect to TeamSpeak-server");
$cyts->login("admin", "pass");
header("Content-type: image/png");
    $bg = "teamspeakimg.png";
    $im = @ImageCreateFromPNG($bg);
 
    $width =1;
    $font  = 2;
    $fonta  = 3;
    $black = imagecolorallocate($im, 255, 255, 255); 
$users = $cyts->admin_dbUserList(); 
$srvinfo = $cyts->info_serverInfo();
$playerlist = $cyts->info_playerNameList( );
$tsusers = $cyts->info_playerList();
for($i=0;$i<count($list);$i++){
  $chanUsers = $cyts->info_channelUser($list[$i]["id"]);
 print_r($chanUsers['nick']); 
$chanUsers[nick]= array("[nick]");
$comma_separated = implode(",", $chanUsers);

}

imagestring($im, 2, 5, 5, $srvinfo["server_currentusers"] , $black);
imagestring($im, 2, 20, 5,"users online", $black);
imagestring($im, 2, 5, 15,$srvinfo["server_name"]  , $black);
imagestring($im, 2, 40, 15,"Server" , $black);
imagestring($im, 2, 5, 25,$srvinfo["server_uptime"]  , $black);
imagestring($im, 2, 50, 25,"seconds up", $black);
imagestring($im, 2, 5, 35,$srvinfo["server_currentchannels"]  , $black);
imagestring($im, 2, 17, 35,"Channels", $black);
imagestring($im, 2, 5, 45, $comma_separated  , $black);


    imagePNG($im);
    ImageDestroy;  
?>
But as you can see it doesnt yeild anything http://jeejee2.100webspace.net/servercount.php
$list isn't initialised (nor does it hold anything) in your image-script.
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

lol good point

Ok I got it to work:

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$cyts->connect("xxx.xx.xxx.xx", 51234, xxxx) or die ("Unable to connect to TeamSpeak-server");

header("Content-type: image/png");
    $bg = "teamspeakimg.png";
    $im = @ImageCreateFromPNG($bg);
 
    $width =1;
    $font  = 2;
    $fonta  = 3;
    $black = imagecolorallocate($im, 255, 255, 255); 

$srvinfo = $cyts->info_serverInfo();
$playerlist = $cyts->info_playerNameList( );
$tsusers = $cyts->info_playerList();
$list = $cyts->info_channelList();
$users = $cyts->admin_dbUserList();
$tsusers = $cyts->info_playerList();
$tsserv = $cyts->info_serverInfo();
foreach ($list as $channel) {

     
        $channel[name]
         ; 
  $chanUsers = $cyts->info_channelUser($channel["id"]);
 foreach($chanUsers as $user) { 
       
         $user[nick]
         ;
   
} }



imagestring($im, 2, 5, 5, $srvinfo["server_currentusers"] , $black);
imagestring($im, 2, 20, 5,"users online", $black);
imagestring($im, 2, 5, 15,  "$user[nick],$user[nick]" , $black);
imagestring($im, 2, 5, 25,$srvinfo["server_name"]  , $black);
imagestring($im, 2, 40, 25,"TeamSpeak Server" , $black);
imagestring($im, 2, 5, 35,$srvinfo["server_uptime"]  , $black);
imagestring($im, 2, 50, 35,"seconds up", $black);
imagestring($im, 2, 5, 45,$srvinfo["server_currentchannels"]  , $black);
imagestring($im, 2, 17, 45,"Channels", $black);



    imagePNG($im);
    ImageDestroy;  
?>
But only one person will show up! If I place two $user[nick] the same person's name will show up twice. Is there a way around this?
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Through a little work and research $user[nick] now shows everyone who logs on. But every name is on top of the other!!!!!!!!!!!!!!!!!!!! argh argh argh. I cant seem to find (nor know where to start) how to make this string $user[nick] to fully expand in an imagecreatefrompng string.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

jeeep wrote:Through a little work and research $user[nick] now shows everyone who logs on. But every name is on top of the other!!!!!!!!!!!!!!!!!!!! argh argh argh. I cant seem to find (nor know where to start) how to make this string $user[nick] to fully expand in an imagecreatefrompng string.
You're using several imagestring functions, right?

Why don't you add the strings?

Code: Select all

$string = "user1, ";
$string .= "user2";
print($string);
Output: user1, user2
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Where exactly would that go in here?

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$cyts->connect("xxx.xx.xxx.xx", 51234, xxxx) or die ("Unable to connect to TeamSpeak-server");
$cyts->login("admin", "pass");
header("Content-type: image/png");
    $bg = "teamspeakimg.png";
    $im = @ImageCreateFromPNG($bg);
 
    $width =1;
    $font  = 2;
    $fonta  = 3;
    $black = imagecolorallocate($im, 255, 255, 255); 

$srvinfo = $cyts->info_serverInfo();
$playerlist = $cyts->info_playerNameList( );
$tsuser = $cyts->info_playerList();
$list = $cyts->info_channelList();
$users = $cyts->admin_dbUserList();
$tsusers = $cyts->info_playerList();
$tsserv = $cyts->info_serverInfo();
$time =(($srvinfo["server_uptime"])*(1/60)*(1/60)) ; 
$time = round($time,2);

foreach ($list as $channel) {
     
        $channel[name]
         ; 
  $chanUsers = $cyts->info_channelUser($channel["id"]);

if (is_array($chanUsers)) {
foreach ($chanUsers as $user) {

        imagestring($im, 1, 300 , 30,$user[nick], $black); 
} }}

imagestring($im, 2, 342, 15,  "Users:" , $black);
imagestring($im, 6, 57, 10,$srvinfo["server_name"]  , $black);
imagestring($im, 2, 167, 58,"Ip: 207.44.140.85:4041"  , $black);
imagestring($im, 4, 111, 10,"TeamSpeak Server" , $black);
imagestring($im, 2, 140, 40, $srvinfo["server_currentusers"] , $black);
imagestring($im, 2, 57, 40,"Users Online:", $black);
imagestring($im, 2, 115, 70,$srvinfo["server_currentchannels"]  , $black);
imagestring($im, 2, 57, 70,"Channels:", $black);
imagestring($im, 2, 115, 100,$time  , $black);
imagestring($im, 2, 57, 100,"Hours Up:", $black);

    imagePNG($im);
    ImageDestroy;  
?>
I tried with no success. Also how would you align that on the x and y axis?
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

jeeep wrote:Where exactly would that go in here?

I tried with no success. Also how would you align that on the x and y axis?

Code: Select all

$users = "";
foreach ($list as $channel) {
  $channel['name'];
  $chanUsers = $cyts->info_channelUser($channel["id"]);
  
  if (is_array($chanUsers)) {
    foreach ($chanUsers as $user) {
      $users .= $user['nick']." ";
    } 
  }
}        
imagestring($im, 1, 300 , 30,$users, $black);
Currently, your string starts at x = 300px (300 pixels between the left side of the image and the start of the string) and at y = 30px (30 pixels from the top of the image to the top of the imagestring). As I don't know how many people are usually online and whether there is a limit as to the length of the nicknames, I can't say whether you'll have to implement a check as to how long $users is (strlen();) as it might get cut off.
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Aerodromoi thanks for being so patient with me and helping me learn php! This last set works greats, just puts all the users in a straight line. I'll look at (strlen() and try and figure that out. Looking over it briefly I think I'll end up using it but right now I'm curious if there is a way to make a box, more or less, that will contain 5 usernames. For example;

Code: Select all

imagestring($im, 1, 200 , 30,$users1, $black);
imagestring($im, 1, 200 , 36 ,$users2, $black);
imagestring($im, 1, 200 , 42 ,$users3, $black);
imagestring($im, 1, 200 , 48 ,$users4, $black);
imagestring($im, 1, 200 , 54 ,$users5, $black);
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

jeeep wrote:Aerodromoi thanks for being so patient with me and helping me learn php! This last set works greats, just puts all the users in a straight line. I'll look at (strlen() and try and figure that out. Looking over it briefly I think I'll end up using it but right now I'm curious if there is a way to make a box, more or less, that will contain 5 usernames. For example;
Just as a hint:

Code: Select all

<?php
   // array containing the individual users
   $userarr     = array("User a","user b","user c","user d"); 
  
   // gd part
   $width       = 80;
   $height      = 16*count($userarr);
   $fontsize    = 2;
			
   $graph_im    = imagecreate($width,$height);
   $white       = imagecolorallocate ($graph_im,255,255,255);	
   $black       = imagecolorallocate ($graph_im,0,0,0);
	
   // create string	
   for($i=0;$i<count($userarr);$i++){
      imagestring($graph_im, $fontsize, 1, ($i*16 + 1),$userarr[$i], $black);
   }
   
   // send header/image
   header ("Content-type: image/png");
   imagepng($graph_im);
   imagedestroy($graph_im);
?>
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

I'm going to stay where I'm at now, seems to be working ok with two users. I'll give that code above a look when I get some time. Thanks for all your help bud! Now I'm going to learn how to do Sessions wooo hooo :D
Post Reply