I can't get account id

Hello i am trying here to get account id but i cant get it i don’t know where is the problem please help me


<?php
/* load system lib */
require_once( RL_LIBS . 'system.lib.php' );

/* redefine page path */
$page_info['Path'] = $pages['browse'];

$period = empty($_GET['nvar_1']) ? $_GET['period'] : $_GET['nvar_1'];

$type = empty($_GET['type']) ? 'sale_rent' : $_GET['type'];
//$disp_type = empty($_GET['type']) ? 'listings' : $_GET['type'];
$period = empty($period) ? 'new' : $period;

/* redefine page name/title */
$bread_crumbs[1]['name'] = $lang['new_'. $disp_type];
$bread_crumbs[1]['title'] = $lang['new_listings'];
$page_info['name'] = $lang['new_'. $disp_type];

if ( $period == 'today' )
{
	$page_info['name'] = $lang['today_'. $disp_type];
	$bread_crumbs[] = array(
		'name' => $lang['today_listings'],
		'title' => $lang['today_'. $disp_type]
	);
	if ( !empty($_GET['type']) )
	{
		$bread_crumbs[1]['vars'] .= "type=" . $_GET['type'];
	}
}

if ( array_key_exists($type, $l_listing_types) )
{
	/* fields for sorting */
	$sorting = array(
		'category' => array(
			'phrase' => $lang['category'],
			'field' => 'Kind_ID'
		),
		'date' => array(
			'phrase' => $lang['date'],
			'field' => 'Pay_date'
		)
	);
	$rlSmarty -> assign_by_ref( 'sorting', $sorting );
	
	/* define sort field */
	$sort_by = empty($_GET['sort_by']) ? $_SESSION['ml_sort_by'] : $_GET['sort_by'];
	if ( !empty($sorting[$sort_by]) )
	{
		$order_field = $sorting[$sort_by]['field'];
	}
	$_SESSION['ml_sort_by'] = $sort_by;
	$rlSmarty -> assign_by_ref( 'sort_by', $sort_by );
	
	/* define sort type */
	$sort_type = empty($_GET['sort_type']) ? $_SESSION['ml_sort_type'] : $_GET['sort_type'] ;
	$sort_type = in_array( $sort_type, array('asc', 'desc') ) ? $sort_type : false ;
	$_SESSION['ml_sort_type'] = $sort_type;
	$rlSmarty -> assign_by_ref( 'sort_type', $sort_type );
	
	/* get listings */
	$reefless -> loadClass('Listings');
	
	$pInfo['current'] = (int)$_GET['pg'];

	if ( $pInfo['current'] > 1 )
	{
		$bc_page = str_replace('{page}', $pInfo['current'], $lang['title_page_part']);
		
		/* add bread crumbs item */
		$bread_crumbs[1]['title'] .= $bc_page;
	}

	$listings = $rlListings -> getListingsByAccount($account_id, $order_field, $sort_type, $pInfo['current'], $config['listings_per_page']);
	$rlSmarty -> assign_by_ref('listings', $listings);
	
	/* get current account */

	$account_info = $rlAccount -> getAccountInfo( $_SESSION['id'] );
	$rlSmarty -> assign_by_ref( 'aInfo', $account_info );
	

	/* get dealer accounts */
	if ($config['mod_rewrite'])
	{
		$var = $_GET['nvar_1'];

		preg_match( '/(.*)-d([0-9]+)/', $var, $id );
		$dealer_id = (int)$id[2];
	}
	else
	{
		$dealer_id = (int)$_GET['id'];
	}
	
	$dealer_id = $listings['Account_ID'];
	$dealer = $rlAccount -> getDealerInfo($dealer_id);
	$rlSmarty -> assign_by_ref('dealer', $dealer);


	/* get seller information */
	/*$start = $start > 1 ? ($start - 1) * $limit : 0;
	$seller_id = $listings[$start]['Account_ID'];
	$seller_info = $rlAccount -> getProfileInfo( $seller_id );
	$rlSmarty -> assign_by_ref( 'seller_info', $seller_info );*/
	
	
	if ( $seller_info['Account_type'] == 'dealer' )
	{
		$dealer_path = (!empty($seller_info['First_name']) || !empty($seller_info['Last_name'])) ? $seller_info['First_name'].' '.$seller_info['Last_name'] : $seller_info['Username'];
		$dealer_path = $rlSmarty -> str2path($dealer_path) . '-d' . $seller_info['ID'];
		$rlSmarty -> assign_by_ref( 'dealer_path', $dealer_path );
		
		$sql = "SELECT COUNT(`T1`.`ID`) AS `count` FROM `" . RL_DBPREFIX . "listings` AS `T1` ";
		$sql .= "LEFT JOIN `" . RL_DBPREFIX . "categories` AS `T2` ON `T1`.`Kind_ID` = `T2`.`ID` ";
		$sql .= "LEFT JOIN `" . RL_DBPREFIX . "listing_plans` AS `T3` ON `T1`.`Plan_ID` = `T3`.`ID` ";
		$sql .= "WHERE `T1`.`Account_ID` = '{$seller_info['ID']}' AND `T1`.`Status` = 'active' AND `T2`.`Type` <> 'advertising'";
		$sql .= "AND UNIX_TIMESTAMP(DATE_ADD(`T1`.`Pay_date`, INTERVAL `T3`.`Days` DAY)) &gt; UNIX_TIMESTAMP(NOW()) ";
		$listing_count = $rlDb -&gt; getRow($sql);
		$seller_info['listings'] = $listing_count['count'];
	}

	/* get additional account fields */
	$additional = $rlAccount -&gt; getAdditional( $seller_id );
	$additional['ID'] = $seller_id;
	$additional_fields = $rlAccount -&gt; getAccountFields( $seller_info['Type_ID'], 'display', $additional);
	$rlSmarty -&gt; assign_by_ref( 'additional_fields', $additional_fields );
	
	$reefless -&gt; loadClass( 'Message' );
	
	if ( !empty($listings) )
	{
	
		/* build rss */
		/*$rss['item'] = 'listings';
		if ($type != 'sale_rent')
			$rss['type'] = $type;
		if ($period != 'new')
			$rss['period'] = $period;
		$rss['title'] = $category['name'];
		$rlSmarty -&gt; assign_by_ref( 'rss', $rss );
		
		/* enable print page */
		/*$print['item'] = 'listings';
		if ($type != 'sale_rent')
			$print['type'] = $type;
		if ($period != 'new')
			$print['period'] = $period;

		$rlSmarty -&gt; assign_by_ref('print', $print);*/
	}
	
	$pInfo['calc'] = $rlListings -&gt; calc;
	$rlSmarty -&gt; assign_by_ref( 'pInfo', $pInfo );
	
	/* register ajax methods */
	$rlXajax -&gt; registerFunction( array( 'addToFavorite', $rlListings, 'ajaxAddToFavorite' ) );
	if ( defined('IS_LOGIN') )
	{
		$rlXajax -&gt; registerFunction( array( 'restoreFavorite', $rlListings, 'ajaxRestoreFavorite' ) );
	}
	
	$rlHook -&gt; load('listingsBottom');
}
else
{
	$sError = true;
}

You’re doing loads of stuff in that code. Where exactly are you trying to get the account id?

Hello guido, here i am trying


    $dealer_id = $listings['Account_ID'];
    $dealer = $rlAccount -> getDealerInfo($dealer_id);
    $rlSmarty -> assign_by_ref('dealer', $dealer); 

its not work for me because there is $key for each listing and i cant get it and if i type like this


    $dealer_id = $listings[0]['Account_ID'];
    $dealer = $rlAccount -> getDealerInfo($dealer_id);
    $rlSmarty -> assign_by_ref('dealer', $dealer); 

its give first account id for listing 0, i hope u understand me

Yes I think I understand. But why is that first account id for listing 0 not ok? What account id do you need?
Did you try a print_r($listings) to see how it is structured?

i want for each listing his account id, like i want to view new listings add to website and i want to view for each listing the name and photo for seller or dealer,
if i use print_r($listings) i will get array like this


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


Then you’ll have to loop through the array with foreach

ya i know, i am sorry but can you help me on this i am new in php :frowning:

maybe like this but its also dosn’t work for me


	foreach ($listings as $key => $value){
	$dealer_id = $listings[$key]['Account_ID'];
	$dealer = $rlAccount -> getDealerInfo($dealer_id);
	$rlSmarty -> assign_by_ref('dealer', $dealer);
	}

its give me account id for first listing


foreach ($listings as $key => $value) {
    $dealer_id = $value['Account_ID'];
    $dealer = $rlAccount -> getDealerInfo($dealer_id);
    $rlSmarty -> assign_by_ref('dealer', $dealer);
}  

Sorrry not working for me i dont know why :((

What does “not working” mean? An error?

look here (i pm you) for each listing have profile pic i want to get it, and look accounts id in array in top


		foreach($listings as $key => $value) {
		    $seller_id =  $value['Account_ID'];
			
			$seller_info = $rlAccount -> getProfileInfo( $seller_id );
			$rlSmarty -> assign( 'seller_info', $seller_info );

			echo $value['Account_ID'];
				}

It looks like the Account_ID is varying, so that should be correct, right?
Then maybe getProfileInfo() is returning the wrong info? Try doing a var_dump of $seller_info.

its get correct info, you can check it

Ok, so the loop gets all the correct info, but it doesn’t display correctly? Then the error might lie in $rlSmarty -> assign( ‘seller_info’, $seller_info ); , but I don’t know smarty, so I can’t help you with that.

its ok, at lest i know now where is the poblem thank you guido2004

Hello guido2004
when i changed your code to


			foreach($listings as $key => $value) {
		    $dealer_id =  $value['Account_ID'];
			
			$dealer = $rlAccount -> getProfileInfo( $dealer_id );
			$rlSmarty -> assign( 'dealer', $dealer );

			var_dump($dealer_id);
				}

i get another array can you check it please??