php - Create a table from an array -
need there 5 servers
$server1 = “1234”; $server2 = “”; $server3 = “5463”; $server4 = “”; $server5 = “1827”;
$server = array($server1, $server2, $server3, $server4, $server5);
then curl initialised
$ch = curl_init(); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_url, "https://api.domain.com/$server1"); curl_setopt($ch, curlopt_returntransfer, 1); $result = curl_exec($ch); $json = json_decode($result, true); $ip = $json[droplet][networks][v4][0][ip_address]; $status = $json[droplet][status]; $currentapp = $json[droplet][image][name]; $hostname = $json[droplet][name]; $memory = $json[droplet][memory]; $cpu = $json[droplet][vcpus]; $disk = $json[droplet][disk];
and result echoed in table :
<tr> <td style="text-align:center"><?php echo $ip; ?></td> <td style="text-align:center"><?php echo $status; ?></td> <td style="text-align:center"><?php echo $currentapp; ?></td> <td style="text-align:center"><?php echo $hostname; ?></td> <td style="text-align:center"><?php echo $memory; ?></td> <td style="text-align:center"><?php echo $cpu; ?></td> <td style="text-align:center"><?php echo $disk; ?></td> </tr>
now please me here how display data of different servers in different rows. , if server 2 , 4 empty server 1 3 , 5 should displayed in 3 rows.
one way of achieving consider servers array . user foreach itereate .
$serverarray = array(); $serverarray[] = '1234'; $serverarray[] = ''; $serverarray[] = '5463'; $serverarray[] = ''; $serverarray[] = '1827'; foreach( $serverarray $servervalue ) { if( $servervalue <> '' ) { $serverurl = 'https://api.domain.com/' .$servervalue; // curl code here // table display code here } }
Comments
Post a Comment