dazholmes Posted February 9 Share Posted February 9 (edited) hi im trying to make a game server page. i have found gameq files which does all the hard work i have it working and printing raw data to the page but i'd like to print them into a table this is what i have so far and it doesn't work if anyone could help id appreciate it. <?php require_once('GameQ/Autoloader.php'); $GameQ = new \GameQ\GameQ(); $GameQ->addServer([ 'type' => 'css', 'host' => '46.105.73.18:27015', ]); $results = $GameQ->process(); print_r($results); ?> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <meta name="description" content="" /> <meta name="author" content="" /> <title>Defcon Gaming</title> <link rel="icon" type="image/x-icon" href="assets/favicon.ico" /> <!-- Font Awesome icons (free version)--> <script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script> <!-- Google fonts--> <link href="https://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet" /> <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet" /> <!-- Core theme CSS (includes Bootstrap)--> <link href="css/styles.css" rel="stylesheet" /> </head> <table class="table table-striped table-dark"> <thead> <tr> <th scope="col">List</th> <th scope="col">Address</th> <th scope="col">Game Type</th> <th scope="col">Server Name</th> <th scope="col">Players</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>List</td> <td> <?php echo $results[gq_gametype]; ?> </td> <!-- how can i print the veriable to this table--> <td> <?php echo $results[gq_hostname]; ?> </td><!-- how can i print the veriable to this table--> <td> <?php echo $results[players]; ?> </td><!-- how can i print the veriable to this table--> </tr> </tr> </tbody> </table> </html> what am i doing wrong with this code? Quote <td> <?php echo $results[gq_gametype]; ?> </td> <!-- how can i print the veriable to this table--> Edited February 9 by dazholmes Quote Link to comment https://forums.phpfreaks.com/topic/326763-print-results-to-html-table/ Share on other sites More sharing options...
mac_gyver Posted February 9 Share Posted February 9 what does the data look like? is there only one row of data or is there a set of rows of data? modern php no longer assumes that unquoted associative array indexes, that are not defined constants, are strings. you must use quotes around associate array indexes. if you tried the above code, did it produce php errors? do you have php's error_reporting set to E_ALL (it should always be this value) and display_errors set to ON, so that php will help you by reporting and displaying all the errors it detects? Quote Link to comment https://forums.phpfreaks.com/topic/326763-print-results-to-html-table/#findComment-1649295 Share on other sites More sharing options...
dazholmes Posted February 9 Author Share Posted February 9 (edited) 20 minutes ago, mac_gyver said: what does the data look like? is there only one row of data or is there a set of rows of data? modern php no longer assumes that unquoted associative array indexes, that are not defined constants, are strings. you must use quotes around associate array indexes. if you tried the above code, did it produce php errors? do you have php's error_reporting set to E_ALL (it should always be this value) and display_errors set to ON, so that php will help you by reporting and displaying all the errors it detects? this is the data i get below, i want to display each array singly into the table like gq_address which is the ip then gq_hostname which is server name then players i had this before but lost all my files years ago just trying to recreate my old server page from 2016 xD Array ( [46.105.73.18:27015] => Array ( [gq_address] => 46.105.73.18 [gq_dedicated] => [gq_gametype] => [gq_hostname] => [gq_joinlink] => steam://connect/46.105.73.18:27015/ [gq_mapname] => [gq_maxplayers] => [gq_mod] => [gq_name] => Counter-Strike: Source [gq_numplayers] => [gq_online] => [gq_password] => [gq_port_client] => 27015 [gq_port_query] => 27015 [gq_protocol] => source [gq_transport] => udp [gq_type] => css [players] => Array ( ) [teams] => Array ( ) ) ) image of the table obv bugged due to php error but i'd like to display the info to the table horizontally image the erorr is Fatal error: Uncaught Error: Undefined constant "gq_gametype" in E:\xampp\htdocs\test.php:44 Stack trace: #0 {main} thrown in E:\xampp\htdocs\test.php on line 44 line 44 <td> <?php echo $results[gq_gametype]; ?> </td> Edited February 9 by dazholmes Quote Link to comment https://forums.phpfreaks.com/topic/326763-print-results-to-html-table/#findComment-1649296 Share on other sites More sharing options...
Barand Posted February 9 Share Posted February 9 I'd do something like this... <?php $data = [ '46.105.73.18:27015' => [ 'gq_address' => '46.105.73.18', 'gq_dedicated' => '', 'gq_gametype' => '', 'gq_hostname' => '', 'gq_joinlink' => 'steam://connect/46.105.73.18:27015/' , 'gq_mapname' => '', 'gq_maxplayers' => '', 'gq_mod' => '', 'gq_name' => 'Counter-Strike: Source' , 'gq_numplayers' => '', 'gq_online' => '', 'gq_password' => '', 'gq_port_client' => 27015 , 'gq_port_query' => 27015 , 'gq_protocol' => 'source' , 'gq_transport' => 'udp' , 'gq_type' => 'css' , 'players' => Array (), 'teams' => Array () ] ] ; $tdata = ''; foreach ($data as $k => $v) { $v = array_filter($v); // get rid of blank values $tdata .= "<table border='1'> <tr><th>Array key</th><th>" . join('</th><th>', array_keys($v)) . "</th></tr>\n"; // output headings $tdata .= "<tr><th class='rowth'>$k</th><td>" . join('</td><td>', array_values($v)) . "</td></tr> // output values </table>\n"; } ?> <html lang='en'> <head> <meta 'charset'='utf-8'> <title>Example</title> <style type='text/css'> table { border-collapse: collapse; margin-bottom: 10px; } th { background-color: #444; color: white; padding: 8px; } .rowth { background-color: #888; } td { padding: 8px; text-align: center; } </style> </head> <body> <?= $tdata ?> </body> </html> Giving ... 1 1 Quote Link to comment https://forums.phpfreaks.com/topic/326763-print-results-to-html-table/#findComment-1649299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.