Two column Loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scturley
Forum Newbie
Posts: 3
Joined: Tue Oct 04, 2011 8:24 am

Two column Loop

Post by scturley »

It has been awhile since I have done much of any PHP and I find myself having problems getting the below example to display in a two column table. Any assistance would be apreciated greatly. My last attempt created an endless loop. This example displays one column with no tables.

Code: Select all

$members=$result->members;
foreach ($members as $member){
	$name=$member->name;
	$missions=$member->missions;
	$rank=$member->rank;
	$lastplayed=$member->lastplayed;
	$LPdate=date('l dS \o\f F Y h:i:s A', $lastplayed);
	echo "Player:&nbsp;&nbsp;<a href=\"playerInfo.php?name=$name\" target=\"_blank\">$name</a>\n";
	echo "Rank: ".$rank."<br />\n";
	echo "Missions: ".$missions."<br />\n";
	echo "Last played: ".$LPdate."<br />\n";
}
Last edited by Benjamin on Tue Oct 04, 2011 12:06 pm, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
MattSheppard
Forum Newbie
Posts: 4
Joined: Tue Oct 04, 2011 8:30 am

Re: Two column Loop

Post by MattSheppard »

Is this coming from an XML parser?
scturley
Forum Newbie
Posts: 3
Joined: Tue Oct 04, 2011 8:24 am

Re: Two column Loop

Post by scturley »

Yes, the API parser strips it down to an object containing multiple arrays
scturley
Forum Newbie
Posts: 3
Joined: Tue Oct 04, 2011 8:24 am

Re: Two column Loop

Post by scturley »

i included some of the code that i include on the page below:

Code: Select all

$ga = new GAAPI("1214","3A80D9D2AF4D4E7");
//$ga->EnableDebug();
     
$result = $ga->Agency("71635");

echo "Agency: ".$result->name."<br>\n";
echo "Alliance: ".$result->allianceName."<br>\n";

echo "<hr>\n";


	public function Agency($agencyid) {
		$xmlstr = $this->GAAPI_api("GetAgencyInfo",
			array("agencyId"=>$agencyid));
		if(!$xmlstr) return FALSE;
		$xmlstr = preg_replace("#<(/?)a:#","<$1",$xmlstr);
		$xml = simplexml_load_string($xmlstr);

		// Initialize blank object
		$result = (object)null;

		// Set status codes
		if(intval($xml->ret_cd) != 0) {
			$result->err = intval($xml->ret_cd);
			$result->errmsg = strval($xml->ret_msg);
		}

		$aXml = $xml->agency->get_agency_detailsResult;
		if($aXml) {
			foreach($aXml as $memXml) {
				$id = intval($memXml->player_id);
				$result->members[$id] = $m = (object)null;
//				$m->id				= $id;
				$m->name			= strval($memXml->player_na);
//				$m->agency			= intval($agencyid);
				$m->agencyName		= strval($memXml->agency_name);
//				$m->alliance		= intval($memXml->alliance_id);
				$m->allianceName	= strval($memXml->alliance_name);
				$m->lastplayed		= strtotime($memXml->lastplayed);
				$m->rank			= strval($memXml->rank);
				$m->missions		= intval($memXml->missions);
				$m->winpercent		= doubleval($memXml->WinPercentage);

				// Only set top info once
				if($result->id) continue;
				$result->id				= $m->agency;;
				$result->name			= $m->agencyName;
				$result->allianceName	= $m->allianceName;
				$result->alliance		= $m->alliance;
			}
		}
		unset($aXml);

		return $result;
	}
$members=$result->members;
foreach ($members as $member){
	$name=$member->name;
	$missions=$member->missions;
	$rank=$member->rank;
	$lastplayed=$member->lastplayed;
	$LPdate=date('l dS \o\f F Y h:i:s A', $lastplayed);
	echo "<p class=\"player\">Player:&nbsp;&nbsp;<a href=\"playerInfo.php?name=$name\" target=\"_blank\">$name</a> &nbsp;&nbsp;<small>(Click on Name to View Player Stats)</small></p>\n";
	echo "<p>Rank: ".$rank."<br />\n";
	echo "Missions: ".$missions."<br />\n";
	echo "Last played: ".$LPdate."<br />\n";
	echo "<br />\n";
	echo "<br />\n";
	echo "</p>\n";
}
Last edited by Benjamin on Tue Oct 04, 2011 12:06 pm, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
Post Reply