0

Hello i am new here also new in php

i have problem with my code

$seller_id = $listings[]['Account_ID'];
$seller_info = $rlAccount -> getProfileInfo( $seller_id );
$rlSmarty -> assign_by_ref( 'seller_info', $seller_info );
i get this error Fatal error: Cannot use [] for reading in

the array is

Array (
    [0] => Array
        (
            [name] => Automobiles
            [ID] => 1
            [Account_ID] => 0
        )
    [1] => Array
        (
            [name] => Automobiles
            [ID] => 2
            [Account_ID] => 1
        )
    )
.
.
.

Please help how i can fix it

3
Contributors
11
Replies
14
Views
5 Years
Discussion Span
Last Post by jone kent
Featured Replies
  • 1
    diafol 3,669   5 Years Ago

    [CODE]foreach($listings as $listing){ $seller_id[] = $listing['AccountID']; }[/CODE] will place all the account ids into an array called $seller_id. That it? Read More

0

You can't get data like this as [] doesn't refer to anything. You can certainly set data like this.

$seller_id = $listings[0]['Account_ID']; //will work
0

Thank you ardav, i know its work like this but its will get just one array details

0

I am sorry, what i want get all arrays for listings (0, 1, 2, ....., etc)

1
foreach($listings as $listing){
  $seller_id[] = $listing['AccountID'];
}

will place all the account ids into an array called $seller_id.

That it?

0

I seem to jump on threads that ardav has posted on a lot, but I wanted to chime in here just to advocate the usage of print_r() and var_dump() when struggling with an array-related issue.

I consider these two functions to be extremely useful, and personally can say that once I started using them, my understanding of (multidimensional) arrays was greatly improved.

0

Yes
Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => ) Output has already been sent to the browser at

0

this suggests that $listing[...] are empty.

Do

print_r($listings);
foreach($listings as $listing){
  $seller_id[] = $listing['AccountID'];
}
print_r($seller_id);

See if this shines any light on it.

0

i attached function for this code i hope it help

Attachments
function getListingsByPeriod( $order = 'ID', $order_type = 'asc', $start = 0, $limit = false, $listings_type = false, $period = false)
	{
		global $sql, $sys_fields;
		
		/* define periods */
		$new_period = $GLOBALS['config']['new_period'];
		$hours = date("G");
		$minutes = date("i");
		$seconds = date("s");

		$today_period = ($hours * 3600) + ($minutes * 60) + $seconds;

		/* define start position */
		$start = $start > 1 ? ($start - 1) * $limit : 0;
		
		/* define system fields */
		$sys_fields = array('ID', 'Account_ID', 'Date', 'Shows', 'Type', 'Path', 'Featured', 'Favorite', 'Main_photo', 'Photos_count');

		$GLOBALS['rlHook'] -> load('byPeriodSysFields');
		
		$sql = "SELECT SQL_CALC_FOUND_ROWS DISTINCT SUBSTRING_INDEX(GROUP_CONCAT(DISTINCT `T6`.`Thumbnail` ORDER BY `T6`.`Type` DESC), ',', 1) AS `Main_photo`, `T1`.*, `T4`.`Path`,";
		
		$sql .= $GLOBALS['config']['grid_photos_count'] ? "COUNT(`T6`.`Thumbnail`) AS `Photos_count`, " : "";
		
		$GLOBALS['rlHook'] -> load('listingsModifyFieldByPeriod');
		
		if ( defined('IS_LOGIN') )
		{
			$sql .= "`T5`.`Account_ID` AS `Favorite`, ";
		}
		$sql .= "IF(UNIX_TIMESTAMP(DATE_ADD(`T1`.`Featured_date`, INTERVAL `T2`.`Days` DAY)) > UNIX_TIMESTAMP(NOW()), '1', '0') `Featured`, `T4`.`Parent_ID`, `T4`.`Key` AS `Cat_key` ";
		$sql .= "FROM `" . RL_DBPREFIX . "listings` AS `T1` ";
		$sql .= "LEFT JOIN `" . RL_DBPREFIX . "listing_plans` AS `T2` ON `T1`.`Plan_ID` = `T2`.`ID` ";
		$sql .= "LEFT JOIN `" . RL_DBPREFIX . "categories` AS `T4` ON `T1`.`Kind_ID` = `T4`.`ID` ";
		if ( defined('IS_LOGIN') )
		{
			$sql .= "LEFT JOIN `" . RL_DBPREFIX . "favorites` AS `T5` ON `T1`.`ID` = `T5`.`Listing_ID` ";
		}
		
		$sql .= "LEFT JOIN `" . RL_DBPREFIX . "listing_photos` AS `T6` ON `T1`.`ID` = `T6`.`Listing_ID` ";

		
		$GLOBALS['rlHook'] -> load('listingsModifyJoinByPeriod');
		
		$sql .= "WHERE UNIX_TIMESTAMP(DATE_ADD(`T1`.`Pay_date`, INTERVAL `T2`.`Days` DAY)) > UNIX_TIMESTAMP(NOW()) ";
		$sql .= "AND `T1`.`Status` = 'active' AND `T4`.`Status` = 'active' ";
		if ( in_array($period, array('new', 'today')) )
		{
			if ( $period == 'new' )
			{
				$sql .= "AND UNIX_TIMESTAMP(DATE_ADD(`T1`.`Pay_date`, INTERVAL {$new_period} DAY)) > UNIX_TIMESTAMP(NOW()) ";
			}
			elseif ( $period == 'today' )
			{
				$sql .= "AND UNIX_TIMESTAMP(DATE_ADD(`T1`.`Pay_date`, INTERVAL {$today_period} SECOND)) > UNIX_TIMESTAMP(NOW()) ";
			}
		}
		
		$GLOBALS['rlHook'] -> load('listingsModifyWhereByPeriod');
		$GLOBALS['rlHook'] -> load('listingsModifyGroupByPeriod');
		
		if ( false === strpos($sql, 'GROUP BY') )
		{
			$sql .= " GROUP BY `T1`.`ID` ";
		}
		
		$sql .= "ORDER BY `Featured` DESC ";
		
		if ( $order )
		{
			if ( $order == 'category' )
			{
				$sql .= ", `T4`.`Path` ".strtoupper($order_type)." ";
			}
			elseif ( $order == 'Featured' )
			{
				$order_type = $order_type == 'asc' ? 'desc' : 'asc';
				$sql .= ", `Featured` ".$order_type." ";
			}
			else
			{
				$sql .= ", `T1`.`{$order}` ".strtoupper($order_type)." ";
			}
		}
		$sql .= "LIMIT {$start}, {$limit}";
		
		$listings = $this -> getAll( $sql );
			
		if ( empty($listings) )
		{
			return false;
		}

		$calc = $this -> getRow( "SELECT FOUND_ROWS() AS `calc`" );
		$this ->calc = $calc['calc'];
		
		foreach ( $listings as $key => $value )
		{
			$category_fields = $this -> getFormFields($listings[$key]);
			$items = $category_fields[$listings[$key]['Kind_ID']]['fields'];
			$out_listings[$key]['name'] = $category_fields[$listings[$key]['Kind_ID']]['name'];

			
			foreach ($sys_fields as $sf)
			{
				$out_listings[$key][$sf] = $listings[$key][$sf];
			}
			
			$first = 1;
			
			foreach ($items as $item => $val)
			{
				$field = $category_fields[$listings[$key]['Kind_ID']]['fields'][$item];

				if ($first != 1)
				{
					$field['value'] = $GLOBALS['rlCommon'] -> adaptValue( $field, $listings[$key][$item], 'listing', $listings[$key]['ID'] );
				}
				else
				{
					if ( $field['Condition'] == 'isUrl' || $field['Condition'] == 'isEmail' )
					{
						$field['value'] = $listings[$key][$item];
					}
					else
					{
						$field['value'] = $GLOBALS['rlCommon'] -> adaptValue( $field, $listings[$key][$item], 'listing', $listings[$key]['ID'] );
					}
				}
					
				$out_listings[$key]['fields'][] = $field;
				
				$first++;
			}
			
			$out_listings[$key]['listing_title'] = $this -> getListingTitle( $listings[$key]['Kind_ID'], $listings[$key] );
		}
		
		unset($category_fields, $listings);

		return $out_listings;
	}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.