Jump to content

Recommended Posts

Hey guys,

 

I would like to take an array returned from an access class and style the data so it looks good. Currently I get this:

 

Array ( [576113096] => Array ( [name] => Nobues [skillintraining] => Fighters [skilllevel] => IV [skillTime] => Array ( [note] => [days] => 2 [hours] => 5 [minutes] => 53 [seconds] => 40 ) [WalletAmount] => 65,508,812.57 ISK ) [1404986087] => Array ( [name] => Lireil Crow [skillintraining] => Astrometric Triangulation [skilllevel] => IV [skillTime] => Array ( [note] => [days] => 1 [hours] => 3 [minutes] => 21 [seconds] => 32 ) [WalletAmount] => 9,177,531.37 ISK ) [217317000] => Array ( [name] => Hansoloo [skillintraining] => Amarr Carrier [skilllevel] => V [skillTime] => Array ( [note] => [days] => 60 [hours] => 22 [minutes] => 26 [seconds] => 33 ) [WalletAmount] => 65,100.15 ISK ) [689240734] => Array ( [name] => Mung Lore [skillintraining] => Torpedoes [skilllevel] => V [skillTime] => Array ( [note] => [days] => 8 [hours] => 9 [minutes] => 30 [seconds] => 3 ) [WalletAmount] => 194,399.22 ISK ) )

 

Obviously that isnt very nice to look at, how would i go about separating each bit of data to style and position?

I thought that too but keep getting an error. The code im using to connectt o the access class and return the array is as follows:

 

<?php
$vars = array('user'=>'demo',
              'password'=>'demo',
              'skey'=>'abc123',
              'request'=>'Dashboard',
              'userID'=>'2');

$data = apiGetD($vars);

function apiGetD($vars) {   
        $accessURL = 'www.eve-tool.com';
        $apiURL = '/api/class/class.access.php';
        $poststring = http_build_query($vars, '', '&');
        $fp = fsockopen($accessURL, 80);

        fputs($fp, "POST " . $apiURL . " HTTP/1.0\r\n");
        fputs($fp, "Host: " .  $accessURL . "\r\n");
        fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
        fputs($fp, "User-Agent: PHPApi\r\n");
        fputs($fp, "Content-Length: " . strlen($poststring) . "\r\n");
        fputs($fp, "Connection: close\r\n\r\n");		

        if (strlen($poststring) > 0)
            fputs($fp, $poststring . "\r\n");

        $contents = "";
        while (!feof($fp)) {
            $contents .= fgets($fp);
        }
        fclose($fp);

        $start = strpos($contents, "\r\n\r\n");

        if ($start !== false) {
            return substr($contents, $start + strlen("\r\n\r\n"));

        }
    }

foreach($data as $key=>$value)
    {
    echo $key.": ".$value;
    } 

 

Warning: Invalid argument supplied for foreach() in E:\xampp\htdocs\test.php on line 50 is what i get.

 

If I remove the foreach at the bottom and just print $data i get the array data back fine.

 

any ideas?

 

 

Ok, how would i change it to return an array? I know that the function that it connects to with fsockopen returns an array so somewhere along the line its becoming a string but im not sure where.

This is the function that apiGetD() connects to:

 

Function GetDashboard($sessionID, $user, $dbc, $api, $dataBase){
$userChars = GetAPIKeys($sessionID, $user, $dbc);

if(!count($userChars) < 1){	
	foreach($userChars as $key => $value){
		if($value["info"]["skilllevel"] > 0){
			$value["info"]["skilllevel"] = SkillLevel($value["info"]["skilllevel"]);

			$tqTime = strtotime($value["info"]["evetime"]);
			$endTime = strtotime($value["info"]["skillTime"]);

			$timeLeft = TimeLeft($endTime, $tqTime);

			$value["return"]["name"] = $value["details"]["name"];
			$value["return"]["skillintraining"] = $api->GetTypeName($value["info"]["skillintraining"], $dataBase);
			$value["return"]["skilllevel"] = $value["info"]["skilllevel"];
			if($ft < 0){
				$value["return"]["skillTime"]["note"] = "Finished";

				$value["return"]["skillTime"]["days"] = abs($timeLeft['days']);
				$value["return"]["skillTime"]["hours"] = abs($timeLeft['hours']);
				$value["return"]["skillTime"]["minutes"] = abs($timeLeft['minutes']);
				$value["return"]["skillTime"]["seconds"] = abs($timeLeft['seconds']);					
			} else {
				$value["return"]["skillTime"]["note"] = "";

				$value["return"]["skillTime"]["days"] = $timeLeft['days'];
				$value["return"]["skillTime"]["hours"] = $timeLeft['hours'];
				$value["return"]["skillTime"]["minutes"] = $timeLeft['minutes'];
				$value["return"]["skillTime"]["seconds"] = $timeLeft['seconds'];
			}
			$value["return"]["WalletAmount"] = number_format($value["details"]["balance"],2)." ISK";

			$returnArray[$key] = $value["return"];
		}
	}
}

return $returnArray;
}

try

<?php
$test = 'Array ( [576113096] => Array ( [name] => Nobues [skillintraining] => Fighters [skilllevel] => IV [skillTime] => Array ( [note] => [days] => 2 [hours] => 5 [minutes] => 53 [seconds] => 40 ) [WalletAmount] => 65,508,812.57 ISK ) [1404986087] => Array ( [name] => Lireil Crow [skillintraining] => Astrometric Triangulation [skilllevel] => IV [skillTime] => Array ( [note] => [days] => 1 [hours] => 3 [minutes] => 21 [seconds] => 32 ) [WalletAmount] => 9,177,531.37 ISK ) [217317000] => Array ( [name] => Hansoloo [skillintraining] => Amarr Carrier [skilllevel] => V [skillTime] => Array ( [note] => [days] => 60 [hours] => 22 [minutes] => 26 [seconds] => 33 ) [WalletAmount] => 65,100.15 ISK ) [689240734] => Array ( [name] => Mung Lore [skillintraining] => Torpedoes [skilllevel] => V [skillTime] => Array ( [note] => [days] => 8 [hours] => 9 [minutes] => 30 [seconds] => 3 ) [WalletAmount] => 194,399.22 ISK ) )';
$test = preg_replace('/\( *\[/','([' ,$test);
$test = preg_replace('/=> ([^\[)]*) *([\[)])/','=> \'\1\' \2', $test);
$test = str_replace("'Array (' ", 'Array (', $test);
$test = preg_replace('/ \[/', ', [',$test);
$test = preg_replace('/[\[\]]/','\'',$test);
eval('$out = '.$test.';');

print_r($out);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.