Page 1 of 2

tables in php

Posted: Thu Jun 29, 2006 5:26 am
by jeeep
is there anyway to make a html table an image in php?

Re: tables in php

Posted: Thu Jun 29, 2006 5:43 am
by aerodromoi
jeeep wrote:is there anyway to make a html table an image in php?
Using fopen, fgets and the gd library, this should be possible.

Posted: Thu Jun 29, 2006 5:53 am
by Jenk
But very 'long'

May we ask for what purpose you desire this functionality?

Posted: Thu Jun 29, 2006 5:56 am
by aerodromoi
Jenk wrote:But very 'long'

May we ask for what purpose you desire this functionality?
I'd say the automatic *transfer* of data from server 1 to server 2... ;)

Posted: Thu Jun 29, 2006 9:19 am
by Ollie Saunders
May we ask for what purpose you desire this functionality?
You know. What we need to is to enforce a new forum rule that says "all posters should provide information on what they are trying to achieve functionality-wise rather than just the specifics of a problem". I read so many posts and very often I can't help but say, out loud, "why do you want to do that?" and they always have some funny reason for it.

Posted: Thu Jun 29, 2006 10:13 am
by aerodromoi
I'd rather like to know whether jeeep means an image built using the data provided by a website (which can be done using regex) or whether he / she means something like http://browsershots.org/.

Posted: Thu Jun 29, 2006 11:29 am
by jeeep
I have this code here for showing stats about my teamspeak server and I'm trying to make it where the stats can be called from flash to load. There are several ways of doing this but I am having problems with the other method. Here is the script:

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
$cyts->connect("xxx.xx.xxx.xx", 51234, xxxx) or print "Cannot connect to server.";
$cyts->login("adminuser", "password");
$list = $cyts->info_channelList();
$users = $cyts->admin_dbUserList();
$tsusers = $cyts->info_playerList();
$tsserv = $cyts->info_serverInfo();
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class=\"team\">";
$server=false;
if ($tsserv[server_name] == NULL) $server=true;
if ($server == true) { echo "<tr><td>The server is Offline</td></tr>"; } else { echo "
     <tr>
        <td colspan=\"3\" align=\"left\" nowrap=\"nowrap\">
        <img src=\"images/teamspeak_online.png\" alt=\"TS server\" width=\"16\" height=\"16\" />
        $tsserv[server_name]
        </td>
      </tr>";}
foreach ($list as $channel) {
echo "
     <tr>
        <td nowrap=\"nowrap\" align=\"left\">
        <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
        <img src=\"images/channel.png\" alt=\"TS channel\" width=\"16\" height=\"16\"  />
        $channel[name]:
         </td>
       </tr>";  
   $chanUsers = $cyts->info_channelUser($channel["id"]);
      foreach ($chanUsers as $user) {
echo "
       <tr>
         <td nowrap=\"nowrap\" align=\"left\">
         <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
         <img src=\"images/treeimage3.png\" alt=\"tree\" width=\"16\" height=\"16\"  />
         <img src=\"images/online.gif\" alt=\"online\" width=\"16\" height=\"16\" />
         $user[nick]
         </td>
       </tr> ";
   }
   
}
echo "
      <tr>
         <td height=\"12\">
         <br />
         <p>
         <img src=\"images/black.gif\" width=100 height=1 vspace=1 alt=\"line\">
         <br /> Members Offline:<br />
         <img src=\"images/black.gif\" width=100 height=1 vspace=1 alt=\"line\">
         </p>
         </td>
      </tr>";
      
foreach ($users as $offline) {
//Go through the memberlist
$online = false;
//At first we believe he/she is offline
foreach ($tsusers as $tsuser)
{
//Go through the list of users which are online in TS
if ($tsuser["loginname"] == $offline[5]) $online = true;
//If someone who is online in TS is logged in with the member's loginname change the status to true
}


//If he is online print nothing else print offline
if ($online ==false) echo "
      <tr>
        <td title=\"last login $offline[4]\" align=\"left\" valign=\"middle\">
        <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
        <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
        <img src=\"images/offline.gif\" alt=\"offline\" width=\"16\" height=\"16\" />
        $offline[5]
        </td>
      </tr>
";
} echo"</table>
       <br />";
?>
For example when I use createimagefrompng and put the strings down, only the ones with one figure work, arrays and what not show nothing. So I was hoping that if I could somehow just turn this whole thing into an image it would be easier!

Posted: Thu Jun 29, 2006 12:02 pm
by aerodromoi
jeeep wrote:I have this code here for showing stats about my teamspeak server and I'm trying to make it where the stats can be called from flash to load. There are several ways of doing this but I am having problems with the other method. Here is the script:

For example when I use createimagefrompng and put the strings down, only the ones with one figure work, arrays and what not show nothing. So I was hoping that if I could somehow just turn this whole thing into an image it would be easier!
Even though flash can load external images, I would stick to loadVars and create the chart in flash or use a dynamic textfield.
As to the latter - even though flash supports html in textfields, you can't just import the whole page...

As to the syntax in your script - you might want to take a look at this:

Code: Select all

echo "text".$tsserv['server_name']."more text";

Posted: Thu Jun 29, 2006 12:40 pm
by Luke
ole wrote:
May we ask for what purpose you desire this functionality?
You know. What we need to is to enforce a new forum rule that says "all posters should provide information on what they are trying to achieve functionality-wise rather than just the specifics of a problem". I read so many posts and very often I can't help but say, out loud, "why do you want to do that?" and they always have some funny reason for it.
I generally make sure to include my purpose when I post a question for this very reason. Often I ask a question and people are like... uhh, there is a WAY easier way to do that. Anyway... carry on. :lol:

Posted: Thu Jun 29, 2006 1:06 pm
by jeeep
Yeah flash doesnt load entire pages, that why I'm aiming at just an image! I in the process of making a new sig (via flash) that has different information on it. One part of the sig loads a particular stat sig that I made, which is a png file so I was hoping to do the same with this teamspeak script. I have made a simple ts (teamspeak) script that shows simple information about the ts server but it doesnt show which users are on.

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$cyts->connect("xxx.xxx.xxx.xx", 51234, xxxx) or die ("Unable to connect to TeamSpeak-server");
$cyts->login("admin", "password");
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();
imagestring($im, $font, 5, 5,$srvinfo["server_currentusers"] , $black);
imagestring($im, $font, 20, 5,"users online", $black);
imagestring($im, $font, 5, 20,$srvinfo["server_name"] , $black);
imagestring($im, $font, 5, 30,$srvinfo["server_uptime"] , $black);



 
    imagePNG($im);
    ImageDestroy;  
?>
All of this comes from Class:CYTS
What I want to do is to stick this into a string but I'm not sure if it is possible and I'm quite sure it isnt supposed to look like this:

Code: Select all

imagestring($im, $font, 5, 40,$tsusers["nick"] , $black);

Here is an excerpt from the Class:CYTS file, to help show you what I'm talking about.

Code: Select all

method info_playerList [line 311]
array info_playerList( )

info_playerList: Returns a list of players that are connected to the server

array:
[0], [unparsed] => Unparsed playerstring
[1], [p_id] => PlayerID
[2], [c_id] => ChannelID
[3], [ps] => Packets sent by server
[4], [bs] => Bytes sent by server
[5], [pr] => Packets received by server
[6], [br] => Bytes received by server
[7], [pl] => Packet Loss
[8], [ping] => Ping
[9], [logintime] => Seconds since Login
[10], [idletime] => Idletime in seconds
[11], [cprivs] => Channelflags (1 - CA, 2 - O, 4 - V, 8 - AO, 16 - AV)
[12], [pprivs] => Serverflags (1 - SA, 2 - Allowed To Register(AR), 4 - R, 8 - ???, 16 - Sticky)
[13], [pflags] => Playerflags (1 - Channel Commander(CC), 2 - Voice Request(VR), 4 - No Whisper(NW), 8 - Away(AW), 16 - Mic Muted(MM), 32 - Snd Muted(SM), 64 - Rec(RC))
[14], [ip] => IP-Adress (Note: This will be 0.0.0.0 for all players if you are not logged in as a server admin)
[15], [nick] => Nickname
[16], [loginname] => Loginname (empty if user is not registered)



Tags:
return:  	multi-dimensional array with player data
access:  	public
see:  	cyts::info_translateFlag(), for converting flags to arrays
version:  	2.0
author:  	Steven Barth

Posted: Thu Jun 29, 2006 1:27 pm
by aerodromoi
You'd only need a loop to output the data. However, it seems to me that

Code: Select all

info_playerList( );
only returns the data concerning one individual player. Or am I missing something?

Posted: Thu Jun 29, 2006 1:49 pm
by jeeep
No your correct, I seem to have overlooked that. It seems as though this part of the php code above get the channels then the users logged into the channels:

Code: Select all

foreach ($list as $channel) {
echo "
     <tr>
        <td nowrap=\"nowrap\" align=\"left\">
        <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
        <img src=\"images/channel.png\" alt=\"TS channel\" width=\"16\" height=\"16\"  />
        $channel[name]:
         </td>
       </tr>"; 
   $chanUsers = $cyts->info_channelUser($channel["id"]);
      foreach ($chanUsers as $user) {
echo "
       <tr>
         <td nowrap=\"nowrap\" align=\"left\">
         <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
         <img src=\"images/treeimage3.png\" alt=\"tree\" width=\"16\" height=\"16\"  />
         <img src=\"images/online.gif\" alt=\"online\" width=\"16\" height=\"16\" />
         $user[nick]
         </td>
       </tr> ";
   }
   
}
Here $user[nick] shows all the players logged into the channels. But is it possible to enter that into this?

Code: Select all

imagestring($im, $font, 5, 45,$user["nick"] , $black);

Posted: Thu Jun 29, 2006 2:00 pm
by aerodromoi
Yup.

Just for orientation, could you post (print_r) the arrays $list and $chanUsers?

What I'm driving at: http://de2.php.net/manual/en/function.implode.php

Posted: Thu Jun 29, 2006 2:46 pm
by jeeep
Sorry m8, not really sure of what your asking for so I'll list all that I know!

$list = $cyts->info_channelList();
$chanUsers = $cyts->info_channelUser($channel["id"]);

Code: Select all

method info_channelList [line 377]
array info_channelList( )

info_channelList: Returns a list of channels that are available on the server

array:
[0], [unparsed] => Unparsed channelstring
[1], [id] => ChannelID
[2], [codec] => Codec (from 0 to 13):
[3], [parent] => Parent ChannelID (-1 if no Subchannel)
[4], [order] => Channel Order
[5], [maxusers] => Max Users
[6], [name] => Name
[7], [flags] => Flags (1 - Unregistered(U), 2 - Moderated(M), 4 - Private(P), 8 - Subchannels(S), 16 - Default(D))
[8], [password] => Passworded (1 - True, 0 - False)
[9], [topic] => Topic



Tags:
return:  	multi-dimensional array with channel data
see:  	cyts::info_getCodec(), for getting a codecs name by its id
see:  	cyts::info_translateFlag(), for converting flags to arrays
access:  	public
version:  	2.0
author:  	Steven Barth


[ Top ]

Code: Select all

method info_channelUser [line 709]
array info_channelUser( integer $cID)

info_channelUser: Returns all users in the target channel in an array



Tags:
return:  	user list, false at failure
see:  	getPlayers(), for an array description
see:  	getChannelByName(), for converting a channel name to an ID
access:  	public
version:  	2.0
author:  	Steven Barth


Parameters:
integer   	$cID   	The Channel ID
Here is the url to the simple teamspeak code I mentioned above: http://jeejee2.100webspace.net/servercount.php

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$cyts->connect("xxxxxxxxxx", 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();
imagestring($im, $font, 5, 5,$srvinfo["server_currentusers"] , $black);
imagestring($im, $font, 20, 5,"users online", $black);
imagestring($im, $font, 5, 20,$srvinfo["server_name"] , $black);
imagestring($im, $font, 5, 30,$srvinfo["server_uptime"] , $black);
imagestring($im, $font, 5, 45,$tsusers["nick"] , $black);


 
    imagePNG($im);
    ImageDestroy;  
?>
and here is the link/code for the other one: http://jeejee2.100webspace.net/ttsphpts.php

Code: Select all

<?php
require("cyts.class.php");
$cyts = new cyts;
$cyts->connect("xxxxxxxxxx", 51234, xxxx) or print "Cannot connect to server.";
$cyts->login("admin", "pass");
$list = $cyts->info_channelList();
$users = $cyts->admin_dbUserList();
$tsusers = $cyts->info_playerList();
$tsserv = $cyts->info_serverInfo();
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class=\"team\">";
$server=false;
if ($tsserv[server_name] == NULL) $server=true;
if ($server == true) { echo "<tr><td>The server is Offline</td></tr>"; } else { echo "
     <tr>
        <td colspan=\"3\" align=\"left\" nowrap=\"nowrap\">
        <img src=\"images/teamspeak_online.png\" alt=\"TS server\" width=\"16\" height=\"16\" />
        $tsserv[server_name]
        </td>
      </tr>";}
foreach ($list as $channel) {
echo "
     <tr>
        <td nowrap=\"nowrap\" align=\"left\">
        <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
        <img src=\"images/channel.png\" alt=\"TS channel\" width=\"16\" height=\"16\"  />
        $channel[name]:
         </td>
       </tr>";  
   $chanUsers = $cyts->info_channelUser($channel["id"]);
if (!empty($chanUsers) && is_array($user))
{       

foreach ($chanUsers as $user) {
echo "
       <tr>
         <td nowrap=\"nowrap\" align=\"left\">
         <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
         <img src=\"images/treeimage3.png\" alt=\"tree\" width=\"16\" height=\"16\"  />
         <img src=\"images/online.gif\" alt=\"online\" width=\"16\" height=\"16\" />
         $user[nick]
         </td>
       </tr> ";
   }}
   
}
echo "
      <tr>
         <td height=\"12\">
         <br />
         <p>
         <img src=\"images/black.gif\" width=100 height=1 vspace=1 alt=\"line\">
         <br /> Members Offline:<br />
         <img src=\"images/black.gif\" width=100 height=1 vspace=1 alt=\"line\">
         </p>
         </td>
      </tr>";
      
foreach ($users as $offline) {
//Go through the memberlist
$online = false;
//At first we believe he/she is offline
foreach ($tsusers as $tsuser)
{
//Go through the list of users which are online in TS
if ($tsuser["loginname"] == $offline[5]) $online = true;
//If someone who is online in TS is logged in with the member's loginname change the status to true
}


//If he is online print nothing else print offline
if ($online ==false) echo "
      <tr>
        <td title=\"last login $offline[4]\" align=\"left\" valign=\"middle\">
        <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
        <img src=\"images/treeimage4.png\" alt=\"blank\" width=\"16\" height=\"16\"  />
        <img src=\"images/offline.gif\" alt=\"offline\" width=\"16\" height=\"16\" />
        $offline[5]
        </td>
      </tr>
";
} echo"</table>
       <br />";
?>

I'll look into that implode code later when I get a chance, for now I have to go look for a cat to adopt for my g/f lol. Thanks for all your help bud. If I didnt answer your question or if you need something else let me know.

Posted: Thu Jun 29, 2006 2:51 pm
by aerodromoi
I just meant:

Code: Select all

$list = $cyts->info_channelList();
$chanUsers = $cyts->info_channelUser($channel["id"]);
print_r($list);
print_r($chanUsers);
to get an overview of the two arrays.