Server query to table HELP

Okay, so I have this code here:

[php]/* SOURCE ENGINE QUERY FUNCTION, requires the server ip:port */
function source_query($ip){
$cut = explode(":", $ip);
$HL2_address = $cut[0];
$HL2_port = $cut[1];

$HL2_command = "\377\377\377\377TSource Engine Query\0";

$HL2_socket = fsockopen("udp://".$HL2_address, $HL2_port, $errno, $errstr,3);
fwrite($HL2_socket, $HL2_command); 
$JunkHead = fread($HL2_socket,4);
$CheckStatus = socket_get_status($HL2_socket);

if($CheckStatus["unread_bytes"] == 0)return 0;

$do = 1;
while($do){
    $str = fread($HL2_socket,1);
    $HL2_stats.= $str;
    $status = socket_get_status($HL2_socket);
    if($status["unread_bytes"] == 0){
           $do = 0;
    }
}
fclose($HL2_socket);

$x = 0;
while ($x <= strlen($HL2_stats)){
    $x++;
    $result.= substr($HL2_stats, $x, 1);    
}

// ord ( string $string );
$result = str_split($result);
$info['network'] = ord($result[0]);$char = 1;
while(ord($result[$char]) != "%00"){$info['name'] .= $result[$char];$char++;}$char++;
while(ord($result[$char]) != "%00"){$info['map'] .= $result[$char];$char++;}$char++;
while(ord($result[$char]) != "%00"){$info['dir'] .= $result[$char];$char++;}$char++;
while(ord($result[$char]) != "%00"){$info['description'] .= $result[$char];$char++;}$char++;
$info['appid'] = ord($result[$char].$result[($char+1)]);$char += 2;        
$info['players'] = ord($result[$char]);$char++;    
$info['max'] = ord($result[$char]);$char++;    
$info['bots'] = ord($result[$char]);$char++;    
$info['dedicated'] = ord($result[$char]);$char++;    
$info['os'] = chr(ord($result[$char]));$char++;    
$info['password'] = ord($result[$char]);$char++;    
$info['secure'] = ord($result[$char]);$char++;    
while(ord($result[$char]) != "%00"){$info['version'] .= $result[$char];$char++;}

return $info;

}

$q = source_query(‘74.91.112.138:27015’);

echo “Server: “.$q[‘name’].”
”;
echo “Gamemode: “.$q[‘description’].”
”;
echo “Map: “.$q[‘map’].”
”;
echo "Players: " .$q[‘players’];
echo “/” .$q[‘max’];

echo ’



Sort by

Server IDMember IDSubmission DateLast Updated DateRatingViewsServer NameIP AddressCurrent PlayersMax PlayersMapStatusGame



Sort order

Ascending (A-Z)Descending (Z-A)



 
		<div class="ipsBox_container">
			<table class="ipb_table topic_list hover_rows">
				<tbody>
					<tr>
						<th class="col_f_icon altrow short">
							&nbsp;</th>
						<th>
							Server Name</th>
						<th>
							IP Address</th>
						<th>
							Current Players</th>
						<th>
							Max Players</th>
						<th>
							Map</th>
						<th>
							Status</th>
						<th>
							Game</th>
					</tr>
					<tr class="__topic ">
						<td class="col_f_icon altrow short">
							&nbsp;</td>
						<td>
								<?php echo "Server: ".$q["name"]?></td>
						<td>
							&nbsp;</td>
						<td>
							&nbsp;</td>
						<td>
							&nbsp;</td>
						<td>
							&nbsp;</td>
						<td>
							<img data-tooltip="Online" height="16px" src="http://hellsgamers.com/public/style_images/hg_v6/statusicons/online.png" /></td>
						<td>
							<img data-tooltip="Garry\'s Mod" height="24px" src="hellsgamers.com/public/style_images/hg_v6/servers/type/garrysmod.png" style="margin:-5px 0px;" /></td>
					</tr>
				</tbody>
			</table>
		</div>';[/php]

And I need to have ( echo “/” .$q[‘max’]; ) in the table. But when I copy the code it brakes, help :frowning:

Please post the line with your new code added :slight_smile:

[php]  


<?php echo "Server: ".$q["name"]?>

 [/php]

Ok, you are nesting echo’s. It just doesn’t look right at all. I have changed the last echo to instead stop php execution and just use html. It seems like it is what you intended to do :slight_smile:

[php]<?php
ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);

/* SOURCE ENGINE QUERY FUNCTION, requires the server ip:port */

function source_query($ip) {
$cut = explode(":", $ip);
$HL2_address = $cut[0];
$HL2_port = $cut[1];
$HL2_command = “\377\377\377\377TSource Engine Query\0”;
$HL2_socket = fsockopen(“udp://” . $HL2_address, $HL2_port, $errno, $errstr, 3);
fwrite($HL2_socket, $HL2_command);
$JunkHead = fread($HL2_socket, 4);
$CheckStatus = socket_get_status($HL2_socket);
if ($CheckStatus[“unread_bytes”] == 0)
return 0;
$do = 1;
while ($do) {
$str = fread($HL2_socket, 1);
$HL2_stats.= $str;
$status = socket_get_status($HL2_socket);
if ($status[“unread_bytes”] == 0) {
$do = 0;
}
}
fclose($HL2_socket);
$x = 0;
while ($x <= strlen($HL2_stats)) {
$x++;
$result.= substr($HL2_stats, $x, 1);
}
// ord ( string $string );
$result = str_split($result);
$info[‘network’] = ord($result[0]);
$char = 1;
while (ord($result[$char]) != “%00”) {
$info[‘name’] .= $result[$char];
$char++;
}$char++;
while (ord($result[$char]) != “%00”) {
$info[‘map’] .= $result[$char];
$char++;
}$char++;
while (ord($result[$char]) != “%00”) {
$info[‘dir’] .= $result[$char];
$char++;
}$char++;
while (ord($result[$char]) != “%00”) {
$info[‘description’] .= $result[$char];
$char++;
}$char++;
$info[‘appid’] = ord($result[$char] . $result[($char + 1)]);
$char += 2;
$info[‘players’] = ord($result[$char]);
$char++;
$info[‘max’] = ord($result[$char]);
$char++;
$info[‘bots’] = ord($result[$char]);
$char++;
$info[‘dedicated’] = ord($result[$char]);
$char++;
$info[‘os’] = chr(ord($result[$char]));
$char++;
$info[‘password’] = ord($result[$char]);
$char++;
$info[‘secure’] = ord($result[$char]);
$char++;
while (ord($result[$char]) != “%00”) {
$info[‘version’] .= $result[$char];
$char++;
}
return $info;
}

$q = source_query(‘74.91.112.138:27015’);
echo "Server: " . $q[‘name’] . “
”;
echo "Gamemode: " . $q[‘description’] . “
”;
echo "Map: " . $q[‘map’] . “
”;
echo "Players: " . $q[‘players’];
echo “/” . $q[‘max’];

?>

Sort by
Server IDMember IDSubmission DateLast Updated DateRatingViewsServer NameIP AddressCurrent PlayersMax PlayersMapStatusGame

Sort order
Ascending (A-Z)Descending (Z-A)

 
  Server Name IP Address Current Players Max Players Map Status Game
  Server: <?= $q["name"] ?>        
[/php]

Thank you! <3 really appreciated!

Sponsor our Newsletter | Privacy Policy | Terms of Service