Jump to content

Add conditions to an array


unemployment

Recommended Posts

How can I add the result of my conditions to the array?  Right now I have this error... Parse error: syntax error, unexpected T_DOUBLE_ARROW

 

while (($row = mysql_fetch_assoc($query)) !== false)
{		
	$partners[] = array(
		'id'				=> $row['id'],
		'firstname'			=> $row['firstname'],
		'lastname'			=> $row['lastname'],
		'username'			=> $row['username'],
		'industry'			=> $row['industry'],
		'stage'				=> $row['stage'],
		'companyid'   		=> $row['companyid'],
		'companytag'   		=> $row['companytag'],
		'gender'			=> $row['gender'],
		'accounttyperaw'	=> $row['accounttype'],
		'accounttype'		=> ($row['accounttype'] == '1') ? 'Entreprenuer' : 'Investor',
		'country'         	=> $row['country'],
		'state'				=> $row['state'],
		'city' 				=> $row['city'],
		'approveddate' 		=> $row['approved_date'],
		'feedid' 			=> $row['FeedId'],
		'feedfirstname'		=> $row['FeedFirstName'],
		'feedlastname' 		=> $row['FeedLastName'],
		'feedusername' 		=> $row['FeedUserName'],
		'action_id' 		=> $row['action_id'],
		'details' 			=> $row['details'],
		'display_name'		=> ucwords("${row['firstname']} ${row['lastname']}"),
		'associate_name'	=> ucwords("${row['FeedFirstName']} ${row['FeedLastName']}"),


	);

	//These conditionals should generate the avatars needed for the ajax. 
	if (($row['accounttype'] == 0 || $row['accounttype'] == 1) && !empty($row['action_id']))
	{
		if (($row['FeedId'] != $user_info['uid']) && (!empty($row['action_id'])) && ($row['accounttype'] !== '') && ($row['action_id'] != 'joinedcompany') && ($row['action_id'] != 'companyprofilepicture'))
		{
			'avatar'	=> getUserAvatar($row['FeedUserName']),
		}
		else if (($row['accounttype'] == '') || ($row['action_id'] == 'joinedcompany') || ($row['action_id'] == 'companyprofilepicture'))
		{
			$ctag		= strtolower($row['companytag']),
			'avatar'	=> getCompanyAvatar($ctag),
		}
		else
		{
			'avatar'	=> getUserAvatar($row['username']),
		}
	}
	else if (($row['accounttype'] != '') && empty($row['action_id']))
	{
		'avatar'	=> getUserAvatar($row['username']),
	}
	else if (($row['accounttype'] == '') && ($row['action_id'] == ''))
	{
		$ctag		= strtolower($row['companytag']),
		'avatar'	=> getCompanyAvatar($ctag),
	}

Link to comment
https://forums.phpfreaks.com/topic/238746-add-conditions-to-an-array/
Share on other sites

You have to use an explicit index variable instead of "[]" so you can add the "avatar" to the array:

<?php
$i = 0;
while (($row = mysql_fetch_assoc($query)) !== false)
{		
	$partners[$i] = array(
		'id'				=> $row['id'],
		'firstname'			=> $row['firstname'],
		'lastname'			=> $row['lastname'],
		'username'			=> $row['username'],
		'industry'			=> $row['industry'],
		'stage'				=> $row['stage'],
		'companyid'   		=> $row['companyid'],
		'companytag'   		=> $row['companytag'],
		'gender'			=> $row['gender'],
		'accounttyperaw'	=> $row['accounttype'],
		'accounttype'		=> ($row['accounttype'] == '1') ? 'Entreprenuer' : 'Investor',
		'country'         	=> $row['country'],
		'state'				=> $row['state'],
		'city' 				=> $row['city'],
		'approveddate' 		=> $row['approved_date'],
		'feedid' 			=> $row['FeedId'],
		'feedfirstname'		=> $row['FeedFirstName'],
		'feedlastname' 		=> $row['FeedLastName'],
		'feedusername' 		=> $row['FeedUserName'],
		'action_id' 		=> $row['action_id'],
		'details' 			=> $row['details'],
		'display_name'		=> ucwords("${row['firstname']} ${row['lastname']}"),
		'associate_name'	=> ucwords("${row['FeedFirstName']} ${row['FeedLastName']}"),


	);

	//These conditionals should generate the avatars needed for the ajax. 
	if (($row['accounttype'] == 0 || $row['accounttype'] == 1) && !empty($row['action_id']))
	{
		if (($row['FeedId'] != $user_info['uid']) && (!empty($row['action_id'])) && ($row['accounttype'] !== '') && ($row['action_id'] != 'joinedcompany') && ($row['action_id'] != 'companyprofilepicture'))
		{
			$partners[$i]['avatar']	= getUserAvatar($row['FeedUserName']),
		}
		else if (($row['accounttype'] == '') || ($row['action_id'] == 'joinedcompany') || ($row['action_id'] == 'companyprofilepicture'))
		{
			$ctag		= strtolower($row['companytag']),
			$partners[$i]['avatar']	= getCompanyAvatar($ctag),
		}
		else
		{
			$partners[$i]['avatar']	= getUserAvatar($row['username']),
		}
	}
	else if (($row['accounttype'] != '') && empty($row['action_id']))
	{
		$partners[$i]['avatar']	= getUserAvatar($row['username']),
	}
	else if (($row['accounttype'] == '') && ($row['action_id'] == ''))
	{
		$ctag		= strtolower($row['companytag']),
		$partners[$i]['avatar']	= getCompanyAvatar($ctag),
	}
	$i++;
}
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.